In migration from hibernate 5.* to 6.* there seems to be an issue that I've not been able to navigate. In hibernate 5.* I have used enumerations for the discriminator-type. This worked very well until this migration effort.
The following scenario:
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.EXISTING_PROPERTY,
property = "type"
)
@JsonSubTypes(
JsonSubTypes.Type(value = GenericAction::class, name = "generic"),
JsonSubTypes.Type(value = BreakAction::class, name = "break")
)
@Entity
@DiscriminatorColumn(name = "type")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
class Action (
@Column(name = "type", updatable = false, insertable = false)
@Enumerated(EnumType.STRING)
var type: ActionType = ActionType.GENERIC, //GENERIC, BREAK
....
)
@Entity
@DiscriminatorValue("GENERIC")
class GenericAction (
...
): Action(ActionType.GENERIC)
@Entity
@DiscriminatorValue("BREAK")
class BreakAction (
...
): Action(ActionType.BREAK)
This worked. It would save either 'GENERIC' or 'BREAK' in the database and create the correct polymorphic sub-type when fetched.
In hibernate 6.* not anymore. The issue I have found is that it tries to compare a String with the ActionType (which obviously does not work).
Tried the following:
@DiscriminatorFormula, this however fails whenever a.createNativeQueryis used.- Not using an Enum, this however creates issues at our JSON serialiser/deserialiser level as those same
@JsonPropertyconversions cannot be done - Tried
@Converteron thetypefield - Dug through the sourcecode to see if I could inject/override or manipulate that Enum/String comparison in any way.
When converting everything to strings, it works to store/fetch data, it however does not allow for the original json-conversion. No matter which way I look, the changes on already existing data would be massive.