Joined Entity is Added to Persistent Set Without Being Fully Initialized
Description
Attachments
1
follows up on
Activity
Show:
Marco Belladelli February 29, 2024 at 10:58 AM
another workaround would be to make the @OneToMany
association FetchType.LAZY
, instead of EAGER
, you can try that if you would prefer to keep the full data in the hashCode
method (note that also removing the hashCode
override and simply relying on the default (System.identityHashCode()
should work).

Zachary Cook February 28, 2024 at 4:50 PM
No problem. In the meantime, I’ve been able to work around the issue by reducing fields used in the “many” entity’s hashCode
to just the String ID field. After making that change, the query returns as expected.
Marco Belladelli February 28, 2024 at 9:37 AM
Hi , thank you for reporting the issue and providing a reproducer. After a quick test, this problem seems to be affecting the current Hibernate version as well. We will try looking into it as soon as possible.
While updating a project from Spring Boot 3.1.2 (Hibernate 6.2.1) to 3.1.8 (Hibernate 6.2.22), retrieving a list of entities by their IDs started to throw a
NullPointerException
from the entity'shashCode
method due to null fields being dereferenced. The null fields are not nullable in the database nor are they nullable in the original Kotlin code. The entities in question are the owning side of an eagerly-fetchedManyToOne
relation and they can be successfully retrieved through the “one” side of the relationship.I went back through Hibernate versions and found that the latest one without the issue was 6.2.7.