Rabi
Rabi

Reputation: 111

Hibernate Envers: how to get the revision_type information for a given revision and a given entity class

I am using Hibernate envers 3.6.3.Final. I can audit table and I can see the _audit table is populated with the revision_number, revision_type and entity data. I am making a history page, where I want to display all revision entries, so that when user clicks a revision id, then I can display the entity data along with revision type i.e. it is added, deleted or modified. I am trying to use AuditQuery, but I am not sure how to get the revision_type information for a given revision and a given entity class. Is is possible to do in AuditQuery ?

I can get the 'RevisionType' info by writing Hibernate query. But I want to reuse any existing framework api for this. In another way, I passed different 'RevisionType' as criteria to AuditQuery (i.e. multiple query for DELETE, INSERT and UPDATE) and check if I get any result, but this is not efficient way.

Upvotes: 3

Views: 3409

Answers (1)

thoredge
thoredge

Reputation: 12601

For what it's worth now. I had the same problem and were able to get the revision type by using the AuditQueryCreator#forRevisionsOfEntity method like this:

List<Object[]> resultList = auditReader.createQuery()
    .forRevisionsOfEntity(entityClass, entityClass.getName(), false, true)
    .add(AuditEntity.revisionNumber().eq(revision)).getResultList();

This return a list of array triplets of changes concerning the specified revision. The array triplet contains the entity, entity information and at last the revision type.

Be sure the set the selectEntitiesOnly argument of AuditQueryCreator#forRevisionsOfEntity to false. If set to true the method will return list of entity objects only.

Hibernate Envers version 4.2.2 is used here.

Upvotes: 4

Related Questions