2013-11-28 115 views
0

我一直在創建審計表。我有兩個集合的一對多關係。一旦相反,另一個不是。可審計加入註釋適用於非反向釋放,但不適用於反向釋放。不產生JPA休眠和審計加入表

我的代碼

@Entity 
@Audited 
@AuditTable(value = "DDD") 
public class Department { 
    @Id 
    @GeneratedValue(strategy= GenerationType.IDENTITY) 
    @Audited 
    private int id; 
    private int age; 

    public int getAge() { 
     return age; 
    } 

    public void setAge(int age) { 
     this.age = age; 
    } 
    private String name; 

    @OneToMany(targetEntity = Professor.class,cascade = CascadeType.ALL) 
    @JoinColumn(name = "dept_id") 
    @AuditJoinTable(name = "abc") 
    private java.util.Collection<Professor> employees; 

    @OneToMany(targetEntity = Address.class, mappedBy = "department")<==inverse relation 
    @AuditJoinTable(name = "def") 
//I tried commenting this out and let the inverse side AuditJoinTable annotation, no luck 
    private java.util.Collection<Address> addresses; 
//Getters and setters remove to reduce clutter 
} 

地址

@Entity 
    @Audited 
    public class Address { 
     @Id 
     @GeneratedValue(strategy= GenerationType.IDENTITY) 
     private int id; 
     @Column 
     private String name; 

     @ManyToOne(cascade = CascadeType.ALL) 
     @AuditJoinTable(name = "def") 
     private Department department; 

教授

@Entity 
@Audited 
public class Professor { 
    @Id 
    @GeneratedValue(strategy= GenerationType.IDENTITY) 
    private int id; 
    @Column 
    private String name; 
    private long salary; 

    @ManyToOne 
    @JoinColumn(name = "dept_id") 
    private Department department; 

} 

當我創建使用hibernate.hbm2ddl.auto 「高清」 autdit表scema。但是,會生成「abc」審計聯接表,並且在更新僱員集合時會記錄審計條目。

我使用 休眠/休眠-envers - 3.6.9.Final JPA 1.0

任何指針讚賞

回答

0

好了很多挖仍然沒有找到一個方法後得到它的工作。但是,Address實體的審計表將具有一個列來跟蹤Department的外鍵。我啓用了

"hibernate.ejb.event.post-update"

那麼任何去除,對於集合類的更新將被跟蹤和地址審計表將被更新。