Auditing @Embeddable @ElementCollection with hibernate-envers

2.1k views Asked by At

I have en Entity containing an @Embeddable @ElementCollection. When trying to persist this I keep getting a NonUniqueObjectException.

@Entity
@Audited
public class Entity(){

    private Long entityId;

    @ElementCollection
    private Set<MyEmbeddableCollection> collections = new HashSet<MyEmbeddableCollection>();

}

@Embeddable
public class myEmbeddableCollection(){
    private String myId;

Looking at the log I can see that Envers doesn't include the myId to the envers table. Only the reference to the entity is included.

[HIST_Entity_collections#{revision_id=DefaultRevisionEntity(id = 3, revisionDate = 2013-sep-04 08:44:56), revisionTyp=ADD, entityId=1}]

I am using hibernate-envers 4.2.0.Final-redhat-1. Does anybody have any solution or explanation to why this is happening?

1

There are 1 answers

1
MystyxMac On

There is a bug in Hibernate, see here, that looks like your problem.

Here is a workaround:

public class FixedDefaultComponentSafeNamingStrategy extends DefaultComponentSafeNamingStrategy {
    @Override
    public String propertyToColumnName(String propertyName) {
        return super.propertyToColumnName(propertyName.replace(".collection&&element.", "."));
    }
}