Hibernate Envers appears not to work with org.hibernate.type.AnyType.
When @Any hibernate annotation is used to describe specific polymorphic mapping use case, auditing with Envers does not work out of the box.
With entity field defined as:
@Any(
metaDef = "PartyMetaDef",
metaColumn = @Column( name = "dest_type" )
)
@JoinColumn( name = "dest_id" )
private Party destination;
where Party is abstract class and finally comes in one of two flavors.
Actual party type is decided via PartyMetaDef, and ends up in dest_type (CHAR) column in database.
Actual parent entity id is stored in dest_id (LONG).
Now, for some reason Envers cannot work with this and gives
org.hibernate.MappingException: Type not supported for auditing: org.hibernate.type.AnyType, on entity MyEntity, property 'destination'.
at org.hibernate.envers.configuration.internal.metadata.AuditMetadataGenerator.throwUnsupportedTypeException(AuditMetadataGenerator.java:764) ~[hibernate-envers-5.4.32.Final.jar:5.4.32.Final]
at org.hibernate.envers.configuration.internal.metadata.AuditMetadataGenerator.addValueInFirstPass(AuditMetadataGenerator.java:212) ~[hibernate-envers-5.4.32.Final.jar:5.4.32.Final]
at org.hibernate.envers.configuration.internal.metadata.AuditMetadataGenerator.addValue(AuditMetadataGenerator.java:316) ~[hibernate-envers-5.4.32.Final.jar:5.4.32.Final]
at org.hibernate.envers.configuration.internal.metadata.AuditMetadataGenerator.addProperties(AuditMetadataGenerator.java:350) ~[hibernate-envers-5.4.32.Final.jar:5.4.32.Final]
Hibernate and Envers versions are both 5.4.32.Final
PartyMetaDef is defined as:
@AnyMetaDefs(
@AnyMetaDef( name= "PartyMetaDef", metaType = "string", idType = "long",
metaValues = {
@MetaValue(value = "C", targetEntity = Contact.class),
@MetaValue(value = "W", targetEntity = Warehouse.class)
}
)
)
Both Contact and Warehouse inherit from Party abstract class.