2

I am trying to implement auditing of entity using spring data envers. I am able to obtain all or single Revision object for entity as

Revisions<Integer, User> revisions = userRepository.findRevisions(id);

I want to get REVTYPE value for particular revision but I don't find any method in Revision class. I can see value of REVTYPE in user_aud table.

How can I get REVTYPE of a Revision?

Thanks.

rolve
  • 10,083
  • 4
  • 55
  • 75
Md Zahid Raza
  • 941
  • 1
  • 11
  • 28

2 Answers2

1
List<Object[]> list = auditReader.createQuery()
//  Creates a query, which selects the revisions, at which the given entity was modified.
    .forRevisionsOfEntity(entityClass, entityClass.getName(), false, true)
// false for Entities only, true for selectDeletedEntities
    .add(AuditEntity.revisionNumber().eq(revision)).getResultList();
// Array will contain entity, entity information and revision type.
fg78nc
  • 4,774
  • 3
  • 19
  • 32
  • thanks for response. I know it is possible to get retype value using hibernate auditReader. Since, I am using spring data envers, so, I wanted to get type of Revision from `Revision` object which is returned by methods of `RevisionRepository`. – Md Zahid Raza Jul 01 '17 at 13:46
  • I believe you can't query directly from Revision object. – fg78nc Jul 01 '17 at 14:03
  • Yes. u are right. I did go through source code of RevisionRepositoryImpl, But I can't find any method returning REVTYPE. – Md Zahid Raza Jul 01 '17 at 16:06
  • You are welcome. Maybe you can contribute or suggest(request feature) to Spring Team. But in general, why not to use auditReader? – fg78nc Jul 01 '17 at 16:08
0

Since Version 2.2.0, you can do this:

revision.getMetadata().getRevisionType()

See Javadoc.

rolve
  • 10,083
  • 4
  • 55
  • 75