We're updating the issue view to help you get more done. 

MappingException occurs when a custom enum type is applied to an audited property.

Description

Lets assume a custom extended implementation of EnumType is at play here.
For this example, no methods need to be overridden; just a custom type name used.

1 2 public class ExtendedEnumType extends org.hibernate.type.EnumType { }

Then the entity definition:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 @Entity(name = "CustomEntity") @TypeDef( name = "extended_enum", typeClass = ExtendedEnumType.class ) public static class CustomEntity { @Id @GeneratedValue private Integer id; @Enumerated(EnumType.STRING) @Audited @Type(type = "extended_enum") private Status status; public enum Status { DRAFT, ARCHIVED } // getter/setters omitted }

This would generate a MappingException when the HBM mapping was being sent from Envers to ORM because the the type parameters being provided by Envers to ORM were incorrect, forcing the code path to take a branch that wasn't compatible with HBM.

In short the type definition was being generated something like:

1 2 3 4 5 6 7 8 <type name="org.hibernate.envers.test.integration.TypeTest$ExtendedEnumType"> <param name="org.hibernate.type.ParameterType.primaryKey">false</param> <param name="org.hibernate.type.ParameterType.accessType">field</param> <param name="org.hibernate.type.ParameterType.propertyName">status</param> <param name="org.hibernate.type.ParameterType.returnedClass">org.hibernate.envers.test.integration.TypeTest$CustomEntity$Status</param> <param name="org.hibernate.type.ParameterType.dynamic">true</param> <param name="org.hibernate.type.ParameterType.entityClass">org.hibernate.envers.test.integration.TypeTest$CustomEntity</param> </type>

The expected result should be

1 2 3 4 <type name="org.hibernate.envers.test.integration.TypeTest$ExtendedEnumType"> <param name="enumClass">org.hibernate.envers.test.integration.TypeTest$CustomEntity$Status</param> <param name="useNamed">true</param> </type>

Environment

None

Status

Assignee

Chris Cranford

Reporter

Chris Cranford

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

5.2.13

Priority

Major