title: JPA Hibernate and AuditJoinTable
body: <p>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 releation but not for the inversed one. </p>
  
  <p>My code</p>
  
  <pre><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&lt;Professor&gt; employees;
  
      @OneToMany(targetEntity = Address.class, mappedBy = "department")&lt;==inverse relation
      @AuditJoinTable(name = "def")
  //I tried commenting this out and let the inverse side AuditJoinTable annotation, no luck 
      private java.util.Collection&lt;Address&gt; addresses;
  //Getters and setters remove to reduce clutter
  }
  </code></pre>
  
  <p>Address</p>
  
  <pre><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;
  </code></pre>
  
  <p>Professor</p>
  
  <pre><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;
  
  }
  </code></pre>
  
  <p>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.</p>
  
  <p>I'm using
   hibernate/hibernate-envers - 3.6.9.Final
   JPA 1.0</p>
  
  <p>Any pointers appreciated </p>