-->
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.  [ 4 posts ] 
Author Message
 Post subject: Transaction.commit() throws NPE?
PostPosted: Tue Dec 16, 2003 6:01 pm 
Beginner
Beginner

Joined: Thu Sep 11, 2003 8:41 am
Posts: 35
Location: Atlanta, GA
Working on a transaction involving 7 different tables.

Before I throw code up since it will require some time...

One of the tables always has an attempt at an insert. This insert will fail sometimes due to a unique constraint error, but I don't care if it does, so I do this...
Code:
         try {
            insert( session, rel );
         }
         catch ( Exception e ) {
            // if unique constraint error, ignore
            // else throw Exception
         }


the insert() method basically wraps session.save(). Nothing happens behind the scenes there.

So before I put the rest of the code, does the session or the transaction track exceptions and fail if there is at least one exception?

Currently, it fails inside the commit() method and I never even see the log entry created by ...

Code:
      log.debug("commit");


Any ideas?

_________________
I am the reason spellcheck was created!!!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 16, 2003 8:06 pm 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
I would not try to ignore some exception considering them "safe".

Documentation is prety clear on this point:

Quote:
7.9.4. Exception handling
If the Session throws an exception (including any SQLException), you should immediately rollback the transaction, call Session.close() and discard the Session instance. Certain methods of Session will not leave the session in a consistent state.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 16, 2003 8:49 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
As Dimas says, the doco is very explicit on this point. There is No Way that we can ensure consistent state b/w the session and the database when an SQLException occurs.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2003 10:08 am 
Beginner
Beginner

Joined: Thu Sep 11, 2003 8:41 am
Posts: 35
Location: Atlanta, GA
I thought that may be an issue.

OK I will query first to see if the record is there.

If I still have a problem after doing this, I will post again in this topic.

Thanks guys.

_________________
I am the reason spellcheck was created!!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.