2

我已经Entity包含一个@Embeddable @ElementCollection. 当试图坚持这一点时,我不断得到一个NonUniqueObjectException.

@Entity
@Audited
public class Entity(){

    private Long entityId;

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

}

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

查看日志,我可以看到 Envers 不包括myIdenvers 表。仅包含对实体的引用。

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

我正在使用 hibernate-envers 4.2.0.Final-redhat-1。有人对为什么会发生这种情况有任何解决方案或解释吗?

4

1 回答 1

1

Hibernate 中有一个错误,请参见此处,这看起来像是您的问题。

这是一种解决方法:

public class FixedDefaultComponentSafeNamingStrategy extends DefaultComponentSafeNamingStrategy {
    @Override
    public String propertyToColumnName(String propertyName) {
        return super.propertyToColumnName(propertyName.replace(".collection&&element.", "."));
    }
}
于 2013-09-04T08:28:05.410 回答