title: Envers: Unidirectional OneToMany without additional audit table?
body: <p>The following database schema:</p>
  
  <p>Employee[EMP_ID (PK), name, salary]</p>
  
  <p>Phone[ID (PK), number_str, OWNER_ID (FK)]</p>
  
  <p>Employee_aud[EMP_ID (PK), REV (PK/FK), REVTYPE, name, salary]</p>
  
  <p>Phone_aud[ID (PK), REV (PK/FK), REVTYPE, number_str]</p>
  
  <p>Employe_phone_aud[REV(PK/FK), OWNER_ID(PK/FK), REVTYPE(PK/FK)]</p>
  
  <p>can be expressed with the following Java Entities:</p>
  
  <p><strong>Employee</strong>:</p>
  
  <pre><code>@Entity
  @Audited
  public class Employee {
  
      @Id
      @GeneratedValue
      @Column(name = "EMP_ID")
      private long id;
  
      @Column
      private String name;
  
      @Column
      private int salary;
  
      @OneToMany
      @JoinColumn(name = "OWNER_ID", referencedColumnName = "EMP_ID")
      private final List&lt;Phone&gt; phones = new ArrayList&lt;Phone&gt;();
  
      public Employee(final String name, final int salary) {
          this.name = name;
          this.salary = salary;
      }
  
      public long getId() {
          return id;
      }
  
      public void setId(final long id) {
          this.id = id;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(final String name) {
          this.name = name;
      }
  
      public int getSalary() {
          return salary;
      }
  
      public void setSalary(final int salary) {
          this.salary = salary;
      }
  
      public void addPhone(final Phone phone) {
          this.phones.add(phone);
      }
  }
  </code></pre>
  
  <p><strong>Phone</strong>:</p>
  
  <pre><code>@Entity
  @Audited
  public class Phone {
  
      @Id
      @GeneratedValue
      private long id;
  
      @Column(name = "number_str")
      private String number;
  
      public Phone(final String number) {
          this.number = number;
      }
  
      public long getId() {
          return id;
      }
  
      public void setId(final long id) {
          this.id = id;
      }
  
      public String getNumber() {
          return number;
      }
  
      public void setNumber(final String number) {
          this.number = number;
      }
  }
  </code></pre>
  
  <p>As you can see, there is a linking table between the auditing tables, but no linking table between the entity tables. In the Hibernate-Envers Developerguide I found the following text:</p>
  
  <blockquote>
    <p>When a collection is mapped using these two (@OneToMany+@JoinColumn) annotations, Hibernate doesn't generate a join table. Envers, however, has to do this, so that when you read the revisions in which the related entity has changed, you don't get false results.</p>
  </blockquote>
  
  <p>This is my interpretation of this text:
  My Employee Entity may belong to many phone entities. If I e.g add a Phone to a certain Employee then my Employee gets modified and thus an audit entry has to be made. Using the mapping above, this would result into an audit entry for the Phone Entity and not for the Employee. This problem is solved using the linking table (as this table describes the changes within the phone-collection owned by the employee).</p>
  
  <p>Now my 3 questions:
  - Do I understand the above statement correct or am I missing something special?
  - If Envers didn't create this linking table, it would also be possible to keep track of these relations by looking at the phone_aud table. Is this true?
  - Is it possible to configure / extend envers to support this behavior?</p>
  
  <p>Note: I am asking the question just because I want to know whether it is possible to get rid of the extra linking table and to get a better understanding why it is needed.</p>
  
  <p>Thank you!</p>