I found an issue after migrating to Hibernate 6 using entity inheritance with InheritanceType.TABLE_PER_CLASS
. Trying to save/retrieve a child entity using a parent repository gets the wrong attribute values. This didn’t happen with Hibernate 5.x.
Save scenario
Given a Parent entity defined with InheritanceType.TABLE_PER_CLASS
and a Child entity that inherits from it. The following sequence persists the wrong attribute value:
- Create a new instance of
Child
with default values - Modify one attribute of
Child
via a member function - Save the
Child
entity - The entry is saved with the original (superclass) value, not the modified one
Inspecting the code I can see that the value saved is the one from the superclass, instead of the value from the child.
Get scenario
The following sequence gets the wrong attribute values:
- Create and persist an instance of
Child
with default values - Get the
Child
entity - The retrieved entity has all its overridden fields set to null, and only id and its own fields are set
Inspecting the code you can see that the values retrieved are only set for the superclass, while the child ones are empty. (See Attachment Screenshot 2023-11-06 at 21.26.10.png)
Sample code
Provided sample code with test cases.