If you use targetAuditMode=RelationTargetAuditMode.NOT_AUDITED on a relation and delete the (non-audited) target entity, queries for audits that contain links to the deleted target entity will throw an exception. Where it is thrown depends on how the source entity is implemented: if it implements hashCode() and includes the target entity in the hash, it'll be deep within the query itself.
Here's a concrete example:
class Foo {
@Audited(withModifiedFlag=true)
String interestingField;
@Audited(targetAuditMode=RelationTargetAuditMode.NOT_AUDITED)
Bar myBar;
publicboolean equals(Object obj) {
// compares interestingField and myBar
}
publicint hashCode() {
// hashes interestingField and myBar
}
}
class Bar {
...
}
Now suppose we issue three transactions:
Transaction 1 creates and persists a Foo and a Bar.
Transaction 2 deletes both the Foo and the Bar.
Transaction 3 queries for all revisions.
The query will throw an exception like so:
javax.persistence.EntityNotFoundException: Unable to find Bar with id 1
at org.hibernate.ejb.Ejb3Configuration$Ejb3EntityNotFoundDelegate.handleEntityNotFound(Ejb3Configuration.java:155)
at org.hibernate.proxy.AbstractLazyInitializer.checkTargetState(AbstractLazyInitializer.java:171)
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:160)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:195)
at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:185)
...
at org.hibernate.envers.tools.Triple.hashCode(Triple.java:74)
at java.util.HashMap.put(HashMap.java:372)
at org.hibernate.envers.reader.FirstLevelCache.putOnEntityNameCache(FirstLevelCache.java:87)
at org.hibernate.envers.entities.EntityInstantiator.createInstanceFromVersionsEntity(EntityInstantiator.java:104)
at org.hibernate.envers.query.impl.RevisionsOfEntityQuery.list(RevisionsOfEntityQuery.java:134)
at org.hibernate.envers.query.impl.AbstractAuditQuery.getResultList(AbstractAuditQuery.java:105)
...
It would be nice to fail gracefully in the face of non-existent entity targets, by nullifying the relation, perhaps.
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira