Joined Entity is Added to Persistent Set Without Being Fully Initialized

Description

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's hashCode 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-fetched ManyToOne 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.

Attachments

1

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.

Fixed

Details

Assignee

Reporter

Worked in

Sprint

Fix versions

Affects versions

Priority

Created February 27, 2024 at 9:46 PM
Updated April 12, 2024 at 6:22 PM
Resolved April 12, 2024 at 4:20 PM