Search code examples
hibernatehibernate-envers

Hibernate Envers generates wrong value for discriminator value in case of joined inheritance with discriminator column


I have a joined inheritance mapping with discriminator column.

Parent entity:

@Entity
@Audited
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "type")
public abstract class ParentEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Column(insertable = false, updatable = false)
    private String type;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }
}

Child entity:

@Audited
@Entity
@DiscriminatorValue("child_1")
public class ChildEntity extends ParentEntity {

    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

}

When I try to persist ChildEntity hibernate envers generates incorrect query that contains fully qualified name of child class plus '_AUD' for discriminator column, here is an example:

insert 
into
    parent_entity_aud
    (revtype, type, id, rev) 
values
(?, 'io.samples.data.jpa.domain.ChildEntity_AUD', ?, ?)

Note that value for type is 'io.samples.data.jpa.domain.ChildEntity_AUD' instead of 'child_1'.

Another observation is if I remove @DicriminatorColumn from parent entity and @DiscriminatorValue from child entity then it works.

Does anybody know how to solve this issue?

P.S. I'm using hibernate 5.0.9.Final.


Solution

  • This appears to be a regression problem with Hibernate 5.x versus the behavior observed with Hibernate 4.3.11.Final. I have logged a jira issue HHH-11133 noting this behavior problem.