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-18489 Lazy, unowned one-to-one associations get loaded eagerly in queries - even with bytecode enhancement #8812

Merged
merged 3 commits into from
Sep 16, 2024

Conversation

dreab8
Copy link
Contributor

@dreab8 dreab8 commented Aug 21, 2024


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-18489


final Set<String> initializedLazyAttributeNames = interceptor.getInitializedLazyAttributeNames();
final Set<String> initializedLazyAttributeNames = interceptor.getInitializedLazyAttributeNames();

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note

Invoking
PersistentAttributeInterceptor.getInitializedLazyAttributeNames
should be avoided because it has been deprecated.
);
if ( set ) {
result = selectedValue;
interceptor.attributeInitialized( fetchGroupAttributeDescriptor.getName() );

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note

Invoking
PersistentAttributeInterceptor.attributeInitialized
should be avoided because it has been deprecated.
@dreab8 dreab8 marked this pull request as ready for review August 22, 2024 12:13
Copy link
Member

@yrodiere yrodiere left a comment

Choose a reason for hiding this comment

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

Thanks. LGTM as long as this passes the test, but I noticed what could be a bug; see below.

@dreab8 dreab8 force-pushed the HHH-18489_2 branch 2 times, most recently from 46c3dbc to 3f8e726 Compare September 3, 2024 08:40
@dreab8
Copy link
Contributor Author

dreab8 commented Sep 12, 2024

@yrodiere I applied your suggestions. What do you think?

Copy link
Member

@yrodiere yrodiere left a comment

Choose a reason for hiding this comment

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

I'm not familiar with that area of the code, but as far as I can tell it makes sense, thank you.

Do you think this can reasonably be backported to 6.6? ("no" is fine by me, I'm just asking)

@dreab8
Copy link
Contributor Author

dreab8 commented Sep 13, 2024

@yrodiere this is the 6.6 bakport

@dreab8 dreab8 requested a review from sebersole September 13, 2024 08:38
@yrodiere
Copy link
Member

Thanks!

So we would be good to merge, but... s390x tests are failing, which may be caused by this PR since the failures on main are different:

@dreab8
Copy link
Contributor Author

dreab8 commented Sep 13, 2024

not sure how the changes in this PR may affect the failing test, trying to re-run the job

@dreab8 dreab8 requested a review from beikov September 13, 2024 13:40
@sebersole
Copy link
Member

lgtm. thanks!

@sebersole sebersole merged commit 2f2dbbe into hibernate:main Sep 16, 2024
22 of 24 checks passed
@jimsimon-wk
Copy link

jimsimon-wk commented Dec 20, 2024

@dreab8 I think I may have found a regression with lazy loaded one-to-one associations. I was able to see some test failures by running the tests in this PR with @BytecodeEnhanced(runNotEnhancedAsWell = true). I put up a branch here to demonstrate that

I encountered these failures when upgrading to Hibernate 6.6 (coming from 6.5) when trying to load models that had lazy one-to-one relationships defined. Additionally, I noticed that the failures were still happening even when I eager-fetched those relations.

The exception I hit my application was

throw new ClassCastException( "Object of type '" + entity.getClass() + "' can't be cast to PersistentAttributeInterceptable" );

I confirmed that enabling bytecode enhancements fixes the exception in my application when using Hibernate 6.6

Please let me know if you'd like to see this issue created as a ticket

@jimsimon-wk
Copy link

jimsimon-wk commented Dec 20, 2024

@sebersole @yrodiere forgot to ping some other members of the Hibernate team on the comment above

@yrodiere
Copy link
Member

yrodiere commented Jan 2, 2025

@jimsimon-wk Tests in this PR would be expected to fail if bytecode enhancement is disabled, because lazy-loaded one-to-one associations can only work with bytecode enhancement.

Now, lazy-loaded one-to-one associations should not make you application fail if you don't have bytecode enhancement -- these associations should just degrade gracefully into being loaded eagerly.

If you can write a reproducer based on https://github.com/hibernate/hibernate-test-case-templates/blob/main/orm/hibernate-orm-6/ where having a lazy-loaded one-to-one association in your model makes Hibernate ORM throw a ClassCastException, then yes, please create an issue and provide that reproducer.

@jimsimon-wk
Copy link

@yrodiere This should do the trick: #9560

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