Mapping Hibernate envers tables

Been wondering for a while if mapping the TABLE_aud as @Entity and @Table would be a good idea or not🤔. Is there some kind of opinion regarding this or not?

Why I’m asking is since I’m doing some complex native queries to join data between different tables with the about using now since I’m currently doing native queries with Hibernate ORM to select out revision numbers from given a couple of filters and feel a lack of support in the AuditReader to use criteria queries or HQL/JPQL to join in conditions from related audit tables or just from the REVINFO table.

You can actually use audit entities in HQL, but the metamodel for the entities might be a bit non-obvious. Look up the metamodel for the fully qualified name of the entity class + _AUD to see what attributes you have available.

You can do something like the following for example:

session.createQuery("select e, a from MyEntity e join my.company.MyEntity_AUD a on e.id = a.originalId.id", Object[].class)
.getResultList();
1 Like