-
1. Re: Can you query for changed Entities only?
adamw May 3, 2009 11:38 AM (in response to brochaxc)Hello,
well, there's:auditReader.createQuery().forEntitiesAtRevision(entityClass, revisionNumber)
to which you can add various Envers-query restrictions. See the docs and javadocs for more info. Is that what you need?
Adam -
2. Re: Can you query for changed Entities only?
brochaxc May 3, 2009 1:51 PM (in response to brochaxc)I think that query will return all the entities - even those that were not changed in that particular revision.
Lets say i run an update that sets a particular flag for 10 users in my users table. And that is recorded as revision 25.
What i need is a way to get only those users that were updated as part of revision 25.
I believeauditReader.createQuery().forEntitiesAtRevision(entityClass, revisionNumber)
will return *all* users that existed at that point - even ones that were not updated.
Thanks,
Brocha -
3. Re: Can you query for changed Entities only?
adamw May 4, 2009 3:10 AM (in response to brochaxc)Hello,
ah yes, you are right.
You could creating a query (revisions-of-entity even) and adding a restriction on the revision number, as if it was a normal property (so: AuditEntity.property("REV").eq(25)). This should work, I think. (replace "REV" with however you've named your revision number property/column)
Adam -
4. Re: Can you query for changed Entities only?
brochaxc May 4, 2009 3:33 AM (in response to brochaxc)Hi Adam,
Thanks for the reply. Actually what you wrote didn't work exactly but it gave me an idea and this gave me the result I wanted:
Assuming User is an audited entity:List<User> users= (List<User>) reader.createQuery() .forRevisionsOfEntity(User.class, true, true) .add(AuditEntity.revisionNumber().eq(25)) .getResultList();
The query above returns only users that were changed as part of revision 25.
Another way that also worked but seems a little uglier:List<User> users= (List<User>)reader.createQuery() .forEntitiesAtRevision(User.class, 25) .add(AuditEntity.revisionNumber().eq(25)) .getResultList();
Thanks,
Brocha