Marco Belladelli (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=637b480...
) *commented* on HHH-16136 (
https://hibernate.atlassian.net/browse/HHH-16136?atlOrigin=eyJpIjoiZTc1ZD...
)
Re: LAZY @ManyToOne may break EAGER @ManyToOne when used on the same entity in a different
parent (
https://hibernate.atlassian.net/browse/HHH-16136?atlOrigin=eyJpIjoiZTc1ZD...
)
Hello Tomas Cerskus (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5f3fc10...
) , thanks for reporting the issue!
I ran some tests with you reproducer and I can say that the problem only occurs when
accessing fields with the dot notation (e.g. order.user.id ) but it doesn’t happen when
using getter methods ( order.getUser().getId() ). This is due to how Hibernate fetches and
initializes associated entities. With version 5 it only worked for this particular case
because the order of initialization for associated entities was different and order.user
was not a HibernateProxy , but this is purely by chance (different property names / JVM
could change this behavior).
Even in Hibernate 5, if you try setting the association to LAZY and manually initializing
the user property (calling for example order.getUser().getName() ), you will see that
accessing the field with the dot notation still yields null , but using getter methods the
values are correct.
Using getter methods for properties should solve all issues. Let me know if I can help you
with anything else.
(
https://hibernate.atlassian.net/browse/HHH-16136#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16136#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100214- sha1:6795dbd )