I use Hibernate Envers to audit my entities.
I have one audited entity, Foo, which has a List<Bar> as properties. However, I don't want to audit the Bar entities. Thus, I wrote that:
@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<Bar> getBars() {
return bars;
}
}
Now, I want to retrieve a revision of Foo:
AuditReader reader = AuditReaderFactory.get(getEntityManager());
Foo revision = (Foo) reader.createQuery().forEntitiesAtRevision(Foo.class, 42).getSingleResult();
Unfortunately, when I want to retrieve all the data (i.e. when it lazy loads the bars), I get the error ORA-00942: table or view does not exist, as it tried to query:
select ... from T_FOO_BAR_AUD x, T_BAR y where ...
I though that using @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED), Hibernate Envers would keep the links with the Bar items of the current entity.
So how can I solve my problem, without having to explicitely audit the tables T_BAR and T_FOO_BAR (the join table)? In others words, when I retrieve the list of bars from my revision entity, I get the list of bars from my current entity (as the links between Foo and Bar are not audited).
Thanks.