-->
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: Workaround for tx.wasCommitted?
PostPosted: Sat Nov 27, 2004 8:01 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Hibernate version:
2.1.7 (previous versions too)
Mapping documents:
not needed
Code between sessionFactory.openSession() and session.close():
see util classes
Full stack trace of any exception that occurs:

Name and version of the database you are using:
tested with Oracle 8i
The generated SQL (show_sql=true):
none
Debug level Hibernate log excerpt:

http://www.hibernate.org/hib_docs/api/n ... Committed()

Hi firends,
to have a transparent and pseudo _automatic_ (don't like this) transaction holding, most of us are working with util classes like the one written by Christian in caveatemptor


Code:
   public static void commitTransaction()
      throws InfrastructureException {
      Transaction tx = (Transaction) threadTransaction.get();
      try {
         if ( tx != null && !tx.wasCommitted()
                     && !tx.wasRolledBack() ) {
            log.debug("Committing database transaction of this thread.");
            tx.commit();
         }
         threadTransaction.set(null);
      } catch (HibernateException ex) {
         rollbackTransaction();
         throw new InfrastructureException(ex);
      }
   }

   /**
    * Rollback the database transaction.
    */
   public static void rollbackTransaction()
      throws InfrastructureException {
      Transaction tx = (Transaction) threadTransaction.get();
      try {
         threadTransaction.set(null);
         if ( tx != null && !tx.wasCommitted() && !tx.wasRolledBack() ) {
            log.debug("Tyring to rollback database transaction of this thread.");
            tx.rollback();
         }
      } catch (HibernateException ex) {
         throw new InfrastructureException(ex);
      } finally {
         closeSession();
      }
   }


i have exactly the same tests in mine to know if a transaction has been committed.
But the Javadoc says :
Quote:
Check if this transaction was successfully committed. This method could return false even after successful invocation of commit().


I've checked with Oracle and it's totally true (so well documented ;)), sometimes after a successfull commit, this method returns true, but sometimes not.
Is it related to jdbc? does JTA offer the same behaviour?

Next question: seeing this, our code might be broken so is there a workaround?
should we manage a boolean inside the util class ?


Have a nice week end

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


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.