Null values persisting/retrieving entity with Inheritance.TABLE_PER_CLASS in Hibernate 6

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:

  1. Create a new instance of Child with default values
  2. Modify one attribute of Child via a member function
  3. Save the Child entity
  4. 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:

  1. Create and persist an instance of Child with default values
  2. Get the Child entity
  3. 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.

The problem is your mapping in combination with a strange design choice of Kotlin data classes. This was reported before and you can read more about it here: [HHH-15874] - Hibernate JIRA

Thanks @beikov , I found that issue later yesterday, so I linked that to my own issue here: [HHH-17365] - Hibernate JIRA.

1 Like