title: How not to audit a join table and related entities using Hibernate Envers?
body: <p>I use Hibernate Envers to audit my entities.</p>
  
  <p>I have one audited entity, <code>Foo</code>, which has a <code>List&lt;Bar&gt;</code> as properties. However, I don't want to audit the <code>Bar</code> entities. Thus, I wrote that:</p>
  
  <pre><code>@Entity
  @Audited
  public class Foo {
  
      @JoinTable(name = "T_FOO_BAR", joinColumns = @JoinColumn(name = "FOO_ID"), inverseJoinColumns = @JoinColumn(name = "BAR_ID"))
      @ManyToMany(cascade = PERSIST)
      @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
      public List&lt;Bar&gt; getBars() {
          return bars;
      }
  
  }
  </code></pre>
  
  <p>Now, I want to retrieve a revision of <code>Foo</code>:</p>
  
  <pre><code>    AuditReader reader = AuditReaderFactory.get(getEntityManager());
      Foo revision = (Foo) reader.createQuery().forEntitiesAtRevision(Foo.class, 42).getSingleResult();
  </code></pre>
  
  <p>Unfortunately, when I want to retrieve all the data (i.e. when it lazy loads the <code>bars</code>), I get the error <code>ORA-00942: table or view does not exist</code>, as it tried to query:</p>
  
  <pre><code>select ... from T_FOO_BAR_AUD x, T_BAR y where ...
  </code></pre>
  
  <p>I though that using <code>@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)</code>, Hibernate Envers would keep the links with the <code>Bar</code> items of the <em>current</em> entity.</p>
  
  <p>So how can I solve my problem, without having to explicitely audit the tables <code>T_BAR</code> and <code>T_FOO_BAR</code> (the join table)? In others words, when I retrieve the list of <code>bars</code> from my revision entity, I get the list of <code>bars</code> from my current entity (as the links between <code>Foo</code> and <code>Bar</code> are not audited).</p>
  
  <p>Thanks.</p>