Search code examples
hibernatehibernate-envers

How to get the state for a given revision for a list of IDs in Envers


I have a project that is using Hibernate Envers to store audit info. Now I have a list of Ids and a revision number and I would like to get the information for the entities in that id list for the given revision.

Is it possible to do so?

My research led me into the AuditReader.getQuery() for which I can create a query forEntitiesAtRevision and so on, but I am not able to send an ID to select the entities I would like.

The problems is that if I can't do that, I would have to make one query per entity, which would cause thousands of requests (I have a list of 1000 ids), or get every entity and query on the Java side, which may also not be so good (I have many entities). Because of that, I may decide to write my own query, something I would like to avoid.


Solution

  • I think you should be able to use AuditEntity.id().in(collectionOfIds) as the constraint for the query.