Hibernate Books

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: Oddity in commitTransaction() in chap 8 HibernateUtil class
PostPosted: Fri Jul 09, 2004 8:36 am 
Beginner
Beginner

Joined: Mon Nov 03, 2003 11:48 pm
Posts: 29
Code:
try{
  threadTransaction.set(null);
    if(tx!=null&&!tx.wasCommited()&&!tx.wasRolledBack())
      tx.commit();
      threadTransaction.set(null);
}catch(HibernateException ex){
  rollbackTransaction();
  throw new InfrastructureException(ex);
}


the first threadTransaction.set(null) is invalid because then you can't rollback. There will be nothing to rollback if the commit fails. Should the second threadTransaction.set(null) be within the if as the indentation suggests or outside of it as the braces suggest?

--Angus


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 09, 2004 8:43 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
I can not find the code you posted in either the MEAP chapter 8 or the CaveatEmptor download. Setting the threadlocal transaction to null before trying to rollback or commit it is fine.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 09, 2004 8:45 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Oh, I looked at the wrong method. Yes, you are right, the first call is incorrect and should have been removed in proofread. I'll make a note to get this fixed again. The CaveatEmptor download has the correct version.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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.