At the moment I am experimenting with the envers library in our application for integration. Whenever I do an getRevisions I only get the revisions for the root entity.
However I expect Envers to be able to get the revisions for the entities in the enclosed collections as well. I tried some custom queries but aren't able to combine the two together via a join or something else.
The entities are as follow:
Entity: form
@Audited
@Entity(name = "Form")
@DisplayProperty(displayProperty1 = "name")
public class Form extends IdentityIdEntity<Integer> {
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@MapKey(name = "id")
private Map<Integer, FormElement> elements = new HashMap<Integer, FormElement>();
}
Entity: FormElement
@Audited
@Entity(name = "FormElement")
@Inheritance(strategy = InheritanceType.JOINED)
@DisplayProperty(displayProperty1 = "name")
public abstract class FormElement extends TranslatableIdentityIdEntity<Integer, FormElementTranslation> implements
Comparable<FormElement> {
@Column(length = 50, nullable = false)
private String name;
}
Service: FormVersioningService
public List<Number> findVersionsOfForm(Form form) {
AuditReader auditReader = AuditReaderFactory.get(sessionFactory.getCurrentSession());
logger.info(auditReader.getRevisions(Form.class, form.getId()).toString());
List resultList = auditReader.createQuery().forRevisionsOfEntity(FormElement.class, false, true)
.addProjection(AuditEntity.revisionNumber()).add(AuditEntity.property("form_id").eq(form.getId()))
.getResultList();
logger.info(resultList);
return null;
}
The first log returns:
INFO: [16, 19, 20, 24]
The second returns:
INFO: [24, 25]
But I'd like to get the following result:
INFO: [16, 19, 20, 24, 25]
I'm using Hibernate 3.5.6 and at the moment it isn't possible to upgrade to a new version, so I'm searching for a solution within this version.
Any help is welcome and will be appreciated