Hibernate Envers审核多对多的复合主键不适用于父类

时间:2016-02-05 11:17:47

标签: spring hibernate hibernate-envers

我有以下实体,有多对多关系。使用@Audited在添加到子类时工作正常,但不适用于所有实体 面临编译错误(例外)

员工类

    @Entity
    @Table(name = EMPLOYEE)
    @Audited
    public class Employee implements java.io.Serializable {

    @EmbeddedId
        @AttributeOverrides({
                @AttributeOverride(name = "Id", column = @Column(name = "ID", nullable = false, length = 50) ),
                @AttributeOverride(name = "department", column = @Column(name = "DEPARTMENT", nullable = false, length = 10) ) })
        private DepartmentId id;

        @Column(name = "NAME", length = 50)
        private String name;

@OneToMany(mappedBy = "key.emp", cascade = { CascadeType.ALL }, fetch = FetchType.EAGER,orphanRemoval=true)
        private Set<EmpAddress> empAddMap = new HashSet<EmpAddress>();


    }

Employee的复合主键类

    @Component
    @Embeddable
    @Audited
    public class DepartmentId implements java.io.Serializable {

        @Column(name = "ID", nullable = false, length = 50)
        private String id;

        @Column(name = "DEPARTMENT", nullable = false, length = 10)
        private String department; 

    }

地址类

    @Entity
    @Table(name = "ADDRESS")
    @Audited
    public class Address implements java.io.Serializable {

        private static final long serialVersionUID = 5070283391974818811L;

        @Id
        @Column(name = "CITY", unique = true, nullable = false, length = 50)
        private String city

        @Column(name = "CONTACT")
        private String contact;

    @OneToMany(mappedBy = "key.address", cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
        private Set<EmpAddress> empAddMap = new HashSet<EmpAddress>();
    }

映射类与Employee和Address

的多对多关系
    @Entity
    @Table(name = "EMPLOYEE_ADDRESS", catalog = "LRR")
    @AssociationOverrides({
            @AssociationOverride(name = "key.emp", joinColumns = { @JoinColumn(name = "ID"),
                    @JoinColumn(name = "DEPARTMENT") }),
            @AssociationOverride(name = "key.address", joinColumns = @JoinColumn(name = "CITY") ) })
    @Audited
    public class EmpAddress {

        @EmbeddedId
        private EmpAddId key = new EmpAddId();

        @Column(name = "STATUS_ID")
        private String statusId;

    }

映射实体的复合主键类

    @Embeddable
    public class EmpAddId implements Serializable {
        @ManyToOne(cascade = CascadeType.ALL)
        private Employee emp;
        @ManyToOne(cascade = CascadeType.ALL)
        private Address address;

1 个答案:

答案 0 :(得分:0)

我认为envers不支持复合ID。这里有一个类似的案例,有一个转机: Composite table with Hibernate Envers

我希望它可以帮到你!