2016-02-05 55 views
0

我有以下實體,具有多對多的關係。使用@Audited在添加到子類但不適用於所有實體時工作正常 面向編譯錯誤(例外)Hibernate Envers審覈多對多複合主鍵不適用於父類

Employee類

@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>(); 


    } 

複合主鍵類爲僱員

@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>(); 
    } 

映射類許多與員工一對多的關係和地址映射實體

@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; 

回答