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

Check if @ManyToOne and @OneToOne associations are unproxied when using bytecode enhancement lazy loading #126

Open
vladmihalcea opened this issue Jan 8, 2021 · 6 comments
Labels
enhancement New feature or request

Comments

@vladmihalcea
Copy link
Owner

As explained by @pblanchardie in this Jira issue. when using bytecode enhancement lazy loading, all @ManyToOne and @OneToOne associations should be unproxied in the following ways:

  1. By setting hibernate.bytecode.allow_enhancement
  2. By annotating the associations with @LazyToOne(LazyToOneOption.NO_PROXY)

Otherwise, the associations are fetched eagerly by some recent Hibernate issues.

@vladmihalcea vladmihalcea changed the title Check if hibernate.bytecode.allow_enhancement_as_proxy is enabledwhen using bytecode enhancement lazy loading Check if @ManyToOne and @OneToOne associations are unproxied when using bytecode enhancement lazy loading Jan 8, 2021
@pblanchardie
Copy link

Note that hibernate.bytecode.allow_enhancement is also causing some weird issues and should be avoided until stable IMO.
It looks like it's still a tech preview in best effort mode, as explained by Steve Ebersole.
eg.:
HHH-14360 (fixed)
HHH-14395
HHH-14396
I'm currently reverting the use of lazy initialization with bytecode enhancement, as it brought more trouble than advantages. Better stick with specific mappings, sub-entities, projections, good old stored functions and views or jOOQ when applicable!

@vladmihalcea vladmihalcea added the enhancement New feature or request label Jan 14, 2021
@pblanchardie
Copy link

Good news from Hibernate:
HHH-13658 - Make NO_PROXY unnecessary was planned for 6.0 and should be applied to 5.4 soon.

There is one left, but it should also be fixed:
HHH-13134 - JOIN FETCH does not work properly with enhanced entities

Looking forward to using bytecode enhancement with lazy initialization without troubles!

@pblanchardie
Copy link

Hi @vladmihalcea,
These issues have been fixed so we should not get OneToOneParentSideEvent anymore when using Hibernate 5.5+.
Related to #120
See https://patriceblanchardie.com/hibernate-lazy-initialization

@vladmihalcea
Copy link
Owner Author

Thanks for the tip. I'll have to test it with the latest 5.5 branch and see what's the best fix for it.

@vladmihalcea vladmihalcea added this to the 2.5.1 milestone Feb 25, 2022
@vladmihalcea
Copy link
Owner Author

@pblanchardie I created #160 and I'll leave this issue open to see whether for 5.3 and 5.4 we need to provide the user with the hint about hibernate.bytecode.allow_enhancement.

@vladmihalcea vladmihalcea removed this from the 2.5.1 milestone Feb 25, 2022
@vladmihalcea
Copy link
Owner Author

vladmihalcea commented Feb 25, 2022

@pblanchardie Check out the 2.5.1 release, as it fixes the OneToOneParentSideEvent issue being triggered if you don't have LazyToOneOption.NO_PROXY annotation.

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

No branches or pull requests

2 participants