-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
HHH-19203 Unexpected association fetch triggered by Bean Validation #9804
base: main
Are you sure you want to change the base?
Conversation
&& Hibernate.isPropertyInitialized( traversableObject, traversableProperty.getName() ); | ||
&& persistenceUnitUtil.isLoaded( traversableObject, traversableProperty.getName() ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hibernate.isPropertyInitialized()
is documented to be a synonym for PersistenceUtil.isLoaded()
, so this should in principle not have fixed anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly, the issue is around uninitialized collections. So what we're trying to do here is add an additional check equivalent to Hibernate.isInitialized(collection)
. Apparently there's an undocumented difference between Hibernate.isPropertyInitialized()
and PersistenceUtil.isLoaded()
for that collections. At minimum we should document that properly/.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then we should maybe also change the documentation, because it's not a synonym.
The PersistenceUnitUtil
implementation is aware of the SessionFactory
and can hence also check laziness of and initialize managed objects that are not enhanced, whereas the Hibernate
class can only deal with bytecode enhanced classes.
This is mostly due to the fact that checking if an attribute is actually initialized, we'd have to be able to access the value of the attribute, which we can't without the SessionFactory
, because we don't have a PropertyAccess
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw, there's a built-in one that relies on the persistence utils:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, with all bytecode enhancement settings currently deprecated, I don't see any uses for Hibernate.isInitialized
anymore. I think at least a documentation update is in order, and would go as far as deprecating the method. I don't think it's possible to reimplement Hibernate.isPropertyInitialized
to align PersistenceUnitUtil.isLoaded
without significant side effects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hibernate does not require the use of the bytecode enhancer, and most people don't use it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sorry I meant Hibernate.isPropertyInitialized
not Hibernate.isInitialized
. Without bytecode enhancement, the only time it returns unintialized (false
) is when the passed in Object entity
itself is a HibernateProxy
returned by emf.getReferenceById
, which is completely covered by Hibernate.isInitialized
.
Thanks for your pull request! This pull request appears to follow the contribution rules. › This message was automatically generated. |
More details on Hibernate forum.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.
https://hibernate.atlassian.net/browse/HHH-19203