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

HHH-19203 Unexpected association fetch triggered by Bean Validation #9804

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Kamii0909
Copy link

@Kamii0909 Kamii0909 commented Feb 26, 2025

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

Comment on lines -97 to +100
&& Hibernate.isPropertyInitialized( traversableObject, traversableProperty.getName() );
&& persistenceUnitUtil.isLoaded( traversableObject, traversableProperty.getName() );
Copy link
Member

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.

Copy link
Member

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/.

Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

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.

Copy link
Member

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.

Copy link
Author

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.

@hibernate-github-bot
Copy link

hibernate-github-bot bot commented Feb 26, 2025

Thanks for your pull request!

This pull request appears to follow the contribution rules.

› This message was automatically generated.

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

Successfully merging this pull request may close these issues.

4 participants