Hi,
i've been looking into the "post commit" events and have a question. The way it should work (i think) is that the events are triggered after a transaction has committed its work, but should not trigger when a rollback is occuring(trigger different events?).
But when i use hibernate 3.2.1.ga with annotations as a entitymanager the events do trigger and im thinking its the afterTransactionCompletion(boolean success) implementations in the insert, update and delete actions.
shouldn't
Code:
public void afterTransactionCompletion(boolean success) throws HibernateException {
EntityPersister persister = getPersister();
if ( success && isCachePutEnabled( persister, getSession() ) ) {
....
}
postCommitInsert();
}
be
Code:
public void afterTransactionCompletion(boolean success) throws HibernateException {
EntityPersister persister = getPersister();
if ( success && isCachePutEnabled( persister, getSession() ) ) {
....
}
if (success) {
postCommitInsert();
} else {
//notification of rollbacks?
}
}
some sample code i use where Bean is a simple bean with a @Entity annotation and a @Id for id :
Code:
Bean b = new Bean();
b.value = "value";
EntityManager em = emf.createEntityManager();
EntityTransaction transaction = em.getTransaction();
transaction.begin();
em.persist(b);
b.value = "other";
em.flush();
em.persist(b);
em.flush();
System.err.println("calling rollback");
transaction.rollback();
Query q = em.createNativeQuery("select * from Bean");
assertTrue(q.getResultList().isEmpty());
output:
Code:
Hibernate: insert into Bean (id, value) values (null, ?)
Hibernate: call identity()
Hibernate: update Bean set value=? where id=?
calling rollback
PostInsertEvent:Bean{id=1, value='other'}
PostUpdateEvent:Bean{id=1, value='other'}
Hibernate: select * from Bean
why does this code trigger the post-commit events? im not commiting anything, im rolling back ....
note, im using the flushes to force the "PostUpdateEvent" without it the insert and update are merged ot one insert.
thanx
bram