Audit tables storing incorrect discriminator value when using JOINED entity inheritance.

Description

Using the following entity configuration:

ParentEntity.java

1 2 3 4 5 6 7 8 9 10 11 @Entity @Audited @Inheritance(strategy = InheritanceType.JOINED) @DiscriminatorColumn(name = "type") public abstract class ParentEntity { @Id @GeneratedValue private Integer id; private String type; /** getter/setters **/ }

ChildEntity.java

1 2 3 4 5 6 7 @Entity @Audited @DiscriminatorValue("child") public class ChildEntity extends ParentEntity { private String name; /** getter/setters **/ }

Hibernate will insert *child* as the discriminator value on the ORM side; however, the fully qualified class name of the audited entity will be used in the envers audit tables.

1 2 3 4 5 6 7 8 9 insert into ParentEntity_AUD (REVTYPE, type, id, REV) values (?, 'org.hibernate.test.stackoverflow.StackoverflowTest$ChildEntity_AUD', ?, ?) 09:08:25,631 TRACE BasicBinder:64 - binding parameter [1] as [INTEGER] - [0] 09:08:25,632 TRACE BasicBinder:64 - binding parameter [2] as [BIGINT] - [1] 09:08:25,632 TRACE BasicBinder:64 - binding parameter [3] as [INTEGER] - [1]

In Hibernate 4.3.11.Final, this wasn't observed and the actual configured discriminator value was used instead. This also introduces a column width problem as column width is configured based on the expected configured values, which are often far shorter than the fully qualified name; causing insertion failures on the Envers side.

Environment

None

Status

Assignee

Chris Cranford

Reporter

Chris Cranford

Fix versions

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

5.1.2
5.2.2
5.0.10

Priority

Major