-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: post-commit-insert events
PostPosted: Mon Jan 22, 2007 4:34 pm 
Newbie

Joined: Mon Jan 22, 2007 3:44 pm
Posts: 3
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.