Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get row count of audit table using hibernate envers

In audit table, there is not such a Criteria that we could use Criteria.setProjection(Projections.rowCount()) to get the row count of the query.

We could use AuditQuery to do similar things. But I couldn't find how to set projections in this case. There is also a setProjection method for AuditQuery, but it takes AuditProjection as parameter. Is there a similar thing that I could setProjection(rowCount)?

Thanks

like image 570
user2807385 Avatar asked Feb 20 '14 19:02

user2807385


1 Answers

You can do a count on a given field, e.g.:

getAuditReader().createQuery()
    .forRevisionsOfEntity(SomeEntity.class, false, true)
    .addProjection(AuditEntity.id().count()).getSingleResult()

Or you can count the revision numbers:

getAuditReader().createQuery()
    .forRevisionsOfEntity(SomeEntity.class, false, true)
    .addProjection(AuditEntity.revisionNumber().count()).getSingleResult()
like image 117
adamw Avatar answered Nov 15 '22 08:11

adamw