-->
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.  [ 3 posts ] 
Author Message
 Post subject: post commit event listeners and failed transactions.
PostPosted: Tue Mar 13, 2007 10:22 pm 
Newbie

Joined: Tue Mar 13, 2007 9:17 pm
Posts: 2
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.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 11, 2008 7:48 am 
Newbie

Joined: Fri Sep 07, 2007 4:53 am
Posts: 2
I've run into exactly the same problem as this.

Does anyone have a work around, is there any way to determine when a post-commit event is generated because the transaction committed successfully rather then being rolled-back?

I'd even be content to subclass EntityDeleteAction and modify the default behaviour, but the class is marked as final. The only solution seems to be to copy/paste the content of EntityDeleteAction into a new class and modify afterTransactionCompletion(boolean success).

Other people must have run into this problem, or is there a better way to listen for successful entity deletions?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 17, 2008 8:55 am 
Newbie

Joined: Tue Jan 15, 2008 12:18 am
Posts: 3
See:
http://opensource.atlassian.com/project ... e/HHH-1582

_________________
Michael Lossos
Software Goodness Limited
http://www.softwaregoodness.com/


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

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.