-->
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: Weird error with rollback, commit and save object
PostPosted: Sat Mar 06, 2010 2:41 pm 
Newbie

Joined: Sat Mar 06, 2010 2:29 pm
Posts: 3
I have the next situation:

- Open transaction xxxx
- Save an object ClassA-> fail
Code:
     Hibernate: /* insert ClassA */ insert into class_a .....
     WARN JDBCExceptionReporter:100 - SQL Error: 1048, SQLState: 23000
     ERROR JDBCExceptionReporter:101 - Column 'cccc' cannot be null

- Rollback transaction xxxx

- Open transaction yyyy
- Save another object of another class ClassB -> Save OK
Code:
  Hibernate: /* insert ClassB */ insert into class_b .....

- Commit transaction yyyy ->
Code:
ERROR AssertionFailure:45 - an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
    org.hibernate.AssertionFailure: null id in [b]ClassA[/b] entry (don't flush the Session after an exception occurs)


So my question is... wth is going on there? Why if Im commiting the save of ClassB it broke in ClassA, which i already rollbacked?

Any clue will be really appreciated, this is making me mad :(


Top
 Profile  
 
 Post subject: Re: Weird error with rollback, commit and save object
PostPosted: Sat Mar 06, 2010 3:04 pm 
Newbie

Joined: Sat Mar 06, 2010 2:29 pm
Posts: 3
I managed to avoid this error closing and reopening session after the rollback but im not sure if this is the right way...


Top
 Profile  
 
 Post subject: Re: Weird error with rollback, commit and save object
PostPosted: Mon Mar 08, 2010 3:34 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Yes it is the correct way. From the documentation at http://docs.jboss.org/hibernate/stable/ ... exceptions

Quote:
If the Session throws an exception, including any SQLException, immediately rollback the database 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: Re: Weird error with rollback, commit and save object
PostPosted: Mon Mar 08, 2010 7:50 am 
Newbie

Joined: Sat Mar 06, 2010 2:29 pm
Posts: 3
Thanks for your reply :)

cheers.


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.