Hibernate version: 3.2.2.ga
Name and version of the database you are using: informix 7.31
Hi,
My database tables include constraints that may stop inserts, modifies and deletes from being committed.
I am registering PostCommitInsertEventListeners, PostCommitUpdateEventListeners and PostCommitDeleteEventListeners. When transactions fail to commit due to constraint violations, the post-commit event listener is still being notified of the database change, even though it wasn't committed.
I have traced this behaviour back to org.hibernate.action.EntityDeleteAction (& Entity*Action). The current code shows:
Code:
public void afterTransactionCompletion(boolean success) throws HibernateException {
if ( getPersister().hasCache() ) {
final CacheKey ck = new CacheKey(
getId(),
getPersister().getIdentifierType(),
getPersister().getRootEntityName(),
getSession().getEntityMode(),
getSession().getFactory()
);
getPersister().getCache().release(ck, lock);
}
postCommitDelete();
}
The postCommitDelete() method will be called (and notify listeners of delete events) independent of whether the transaction completed successfully or not. I have changed this method to:
Code:
public void afterTransactionCompletion(boolean success) throws HibernateException {
if ( getPersister().hasCache() ) {
final CacheKey ck = new CacheKey(
getId(),
getPersister().getIdentifierType(),
getPersister().getRootEntityName(),
getSession().getEntityMode(),
getSession().getFactory()
);
getPersister().getCache().release(ck, lock);
}
if (success)
postCommitDelete();
}
and now obtain the behaviour that I expect (that is, the post commit event listener is only notified when the transaction is committed successfully). Similar changes can be applied to the other org.hibernate.action.Event*Action classes.
Is this a bug or am I using the post-commit event listeners the wrong way? If so, how do I determine when post-commit events are generated because the transaction has been committed (as opposed to rolled-back)?
Thanks,
Daniel.