【发布时间】:2013-12-14 16:42:48
【问题描述】:
我无法创建审计表。我有两个集合一对多的关系。一次是相反的,另一个不是。 auditjointable 注释适用于非反向关系,但不适用于反向关系。
我的代码
@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 创建 scema 时,不会生成“def”autdit 表。但是会生成“abc”审计联合,当员工集合更新时,审计条目会被记录。
我正在使用 休眠/休眠环境 - 3.6.9.Final JPA 1.0
任何指针表示赞赏
【问题讨论】: