Hi,
Marry X'mas :)
I'm stuck with creating audit tables. I have two collections one-to-many relationships. Once is inverse, other one is not. The auditjointable annotation works for non-inversed relation but not for the inversed one. Here's my code.
Department class
Code:
@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
}
Address class
Code:
@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;
Professor
Code:
@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;
}
When I create the scema using hibernate.hbm2ddl.auto "def" autdit table is not generated. However "abc" audit jointable is generated and when the employees collection is updated the audit entries are logged.
I'm using hibernate/hibernate-envers - 3.6.9.Final JPA 1.0
Tested with hibernate 4 as well no luck.
Did more investigations and added my own AuditEventListener and debuged initialize(Configuration cfg) method. It seems configuration does contain the non-inverse side audit table but not the inverse side audit table (along with may other info). So it seems like I'm annotating it wrong (or bug in annotation ?)
Any pointers appreciated