Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude the properties market as _metadata_ #208

Open
itsravi77 opened this issue Jan 24, 2019 · 7 comments
Open

Exclude the properties market as _metadata_ #208

itsravi77 opened this issue Jan 24, 2019 · 7 comments

Comments

@itsravi77
Copy link

How can I exclude the properties marked as metadata? I keep getting the exception with message "java.lang.UnsupportedOperationException: org.hibernate.SessionFactory.getAllClassMetadata is no longer supported" on propertyname "allClassMetadata" and source is org.hibernate.internal.SessionFactoryImpl.

In fact ideally I would want to exclude all the fields from SessionFactoryImpl class. I have tried many ways but fails to achieve the result.

@SQiShER
Copy link
Owner

SQiShER commented Jan 24, 2019

Here are some examples about exclusion, that should point you in the right direction. The one in line 48 seems like the most promising one for your scenario.

@SQiShER
Copy link
Owner

SQiShER commented Jan 24, 2019

However, I'm not sure you really want to diff the SessionFactory. Maybe it would be better just to ignore the entire type.

@itsravi77
Copy link
Author

Thanks Daniel. Yes I would like to ignore whole of SessionFactory object. I did try to do it by setting the exclusion type to SessionFactoryImpl.class but it didn’t work.

@SQiShER
Copy link
Owner

SQiShER commented Jan 24, 2019

It has been ages since I've used Hibernate, so I'm just guessing here, but could it be that the SessionFactory is not an instance of SessionFactoryImpl but of SessionFactoryDelegatingImpl?

@itsravi77
Copy link
Author

It’s other way. SessionFactoryImpl is implementation of SessionFactory. I noticed in your example “objectDifferBuilder.inclusion().exclude().type(ArrayList)”, Do we need to say ArrayList.class?

@itsravi77
Copy link
Author

Hi Daniel, I fixed the issue by adding following exclusions:

ObjectDiffer objectDiffer = ObjectDifferBuilder.startBuilding() .inclusion().exclude().propertyName("handler").and() .inclusion().exclude().propertyName("hibernateLazyInitializer").and() .build();
But interestingly, now I don't see it throwing exception if I remove those exclusions, nothing has changed as well. And I see these log entries:

2019-01-25 18:13:57 [http-nio-0.0.0.0-8899-exec-1] WARN d.d.d.c.CircularReferenceService - Detected circular reference in node at path /country/handler/session/delegate. Going deeper would cause an infinite loop, so I'll stop looking at this instance along the current path. 2019-01-25 18:13:57 [http-nio-0.0.0.0-8899-exec-1] WARN d.d.d.c.CircularReferenceService - Detected circular reference in node at path /country/handler/session/session. Going deeper would cause an infinite loop, so I'll stop looking at this instance along the current path. 2019-01-25 18:13:57 [http-nio-0.0.0.0-8899-exec-1] WARN d.d.d.c.CircularReferenceService - Detected circular reference in node at path /country/hibernateLazyInitializer/session/delegate. Going deeper would cause an infinite loop, so I'll stop looking at this instance along the current path. 2019-01-25 18:13:57 [http-nio-0.0.0.0-8899-exec-1] WARN d.d.d.c.CircularReferenceService - Detected circular reference in node at path /country/hibernateLazyInitializer/session/session. Going deeper would cause an infinite loop, so I'll stop looking at this instance along the current path.

Any reason what has changed?

@SQiShER
Copy link
Owner

SQiShER commented Jan 25, 2019

Glad it works now. It's hard to tell what has changed. Didn't Hibernate have some kind of mechanism to attach and detach objects from it? Maybe your object is in detached state and wasn't before? It's really hard to say without seeing your code. And even then it might be some strange little detail. Looking at the reported circular references I'm kinda worried, your object might not be the best target for the object differ. Especially hibernateLazyInitializer and session look like properties that just should not be part of the comparison. Maybe you can make it easier on yourself if you wrap your class in a facade that just exposes the important parts of your data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants