-
1. Re: How to get Revisions for entities obtained with AuditReader.forEntitiesAtRevision()?
adamw Jun 2, 2011 6:30 AM (in response to sebp)Ah, but wait, if you have the revision number, there is only one revision entity for the whole transaction, and you can obtain it using auditReader.findRevision. What you can't do right now easily is get the revision types for each entity (ADD, MOD, DEL).
Adam -
2. Re: How to get Revisions for entities obtained with AuditReader.forEntitiesAtRevision()?
sebp Jun 2, 2011 6:43 PM (in response to adamw)Yes, I have the revision number, but the forEntitiesAtRevision query returns all entities that exist at this revision. And for all of these entities I want to have the revision information of their last change. I solved it this way:
AuditReader reader = AuditReaderFactory.get(em);
// query for revision number and revision type of each entity
AuditQuery q = reader
.createQuery()
.forEntitiesAtRevision(entityClass, revisionNumber)
.addProjection(AuditEntity.revisionNumber())
.addProjection(AuditEntity.revisionType())
.add(AuditEntity.relatedId(relatedEntityName).eq(
relatedEntityId));
List<Object[]> revisionNumberAndType = q.getResultList();
// query for the entities
q = reader
.createQuery()
.forEntitiesAtRevision(entityClass, revisionNumber)
.add(AuditEntity.relatedId(relatedEntityName).eq(
relatedEntityId));
//
List<A> entities = q.getResultList();
List<Object[]> result = new ArrayList<Object[]>(entities.size());
for (int i = 0, size = entities.size(); i < size; i++) {
Object[] o = new Object[3];
o[0] = entities.get(i);
o[1] = reader.findRevision(AuditRevisionEntity.class,
(Number) revisionNumberAndType.get(i)[0]);
o[2] = revisionNumberAndType.get(i)[1];
result.add(o);
}
Each element in the result list is an Object[] with three elements, the entity, its revision entity and the revision type. Is their an easier way to get this?
-
3. Re: How to get Revisions for entities obtained with AuditReader.forEntitiesAtRevision()?
adamw Jun 3, 2011 9:31 AM (in response to sebp)But the revision entity is all the same for each of those entities. So you are after the revision type, yes?
Adam
-
4. Re: How to get Revisions for entities obtained with AuditReader.forEntitiesAtRevision()?
sebp Jun 3, 2011 2:31 PM (in response to adamw)No, the revision entities are different because the entities have changed at different times.
-
5. Re: How to get Revisions for entities obtained with AuditReader.forEntitiesAtRevision()?
adamw Jun 8, 2011 2:35 PM (in response to sebp)Ah, now I finally understood what you are trying to do - sorry .
I don't think there's an easier way to do that right now. Feel free to post a JIRA feature request, maybe with a proposition of a nice general API that shold be implemented?
Adam