How to get the number of rows of an audit table using sleep mode

There are no criteria in the audit table that we can use Criteria.setProjection(Projections.rowCount())to get the number of query lines.

We could use AuditQuery to do this. But I could not find how to set forecasts in this case. There is also a method setProjectionfor AuditQuery, but it takes a parameter AuditProjectionas a parameter. Is there something similar that I could setProjection(rowCount)?

thanks

+4
source share
1 answer

You can do the counting in a given field, for example:

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

Or you can count the version numbers:

getAuditReader().createQuery()
    .forRevisionsOfEntity(SomeEntity.class, false, true)
    .addProjection(AuditEntity.revisionNumber().count()).getSingleResult()
+7
source

Source: https://habr.com/ru/post/1527980/


All Articles