Two classes are given, and they are related via a OneToOne relationship:
@Audited
public class MyClass {
@OneToOne
@Cascade(value = CascadeType.ALL)
private MyOtherClass otherClass;
}
@Audited
public class MyOtherClass {
}
The property "org.hibernate.envers.store_data_at_delete" is set to true, and when auditquerying for the deleted objects and initiliazing the otherClass (an entity which is also deleted) property, and ObjectNotFoundExceptions is thrown. It seems that the proxies do not look for deleted entities, because the same query works fine for the entities of revision type 'ADD' and 'MOD'. The code of the query:
AuditQuery queryDeleted = reader.createQuery().forRevisionsOfEntity(
MyClass.class, false, true).add(
AuditEntity.revisionType().eq(RevisionType.DEL));
List queryResult = queryDeleted.getResultList();
List<MyClass> result = new ArrayList<MyClass>();
for (Object object : queryResult) {
Object[] oArray = (Object[]) object;
MyClass c = (MyClass) oArray[0];
Hibernate.initialize(c.getOtherClass());
}
Forum post with Adam Warski's response:
http://community.jboss.org/thread/160939?tstart=0
Hibernate 3.5.6, Oracle 10 DB
I would greatly appreciate that.
To summarize:
*-to-one proxies fixed in versions 4.2.1 and 4.3.0.Beta2 onwards.
collection proxies fixed in versions 4.2.6 and 4.3.0.Beta4 onwards.
Spring 4.0RC1 + Hibernate 4.3.0.CR1 => OneToOne (failed) OneToMany (failed if the version assign to Integer.MAX_VALUE, success for exact audit version)
Spring 4.0RC1 + Hibernate 4.3.0.Beta5 => OneToOne (failed) OneToMany (failed if the version assign to Integer.MAX_VALUE, success for exact audit version)
Spring 4.0RC1 + Hibernate 4.3.0.Beta4 => OneToOne (failed) OneToMany (failed if the version assign to Integer.MAX_VALUE, success for exact audit version)
a little strange. I am not sure the 4.3.0.Beta4 had apply the patch.
the 4.3.0.Beta4 seem generate query like
change the test code seem can work in beta4