-->
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: Tran rolled back but Hibernate thinks objects were persisted
PostPosted: Tue May 03, 2005 3:27 pm 
Newbie

Joined: Sat Jan 29, 2005 7:09 am
Posts: 11
I attempt to persist 3 new objects (i.e. transient ones that do not yet exist in the database) to the database in a single transaction.

The first 2 inserts are OK, but the third insert throws an exception (I put a CallbackException into the Interceptor to do this). When the transaction rolls back none of the records exist in the database, which is good.

I dump the session and create a new one, and then attempt to save the same 3 objects again, but this time without throwing the CallbackException. However, it seems that that even though the transaction was rolled back, Hibernate thinks that the first two objects were saved successfully (it does not try to insert them into the database, even though they don't exist there). This is probably because during the first attempt Hibernate gave the objects non-null identifiers?

What should I do - should I manually set the identifiers to null when the transaction rolls back?? This seems a bit clunky...

Can anyone help me??

Thanks,

Doug.



Hibernate version: 2.1.8

Name and version of the database you are using: MySQL 4.0


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 03, 2005 8:33 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Its up to you (the developer) to 'rollback' to an acceptable domain object state if you are trying to recover that state after an Tx Exception. Most situations you throw the session and related state away. Ready to start again.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 13, 2005 6:44 pm 
Expert
Expert

Joined: Thu Jan 08, 2004 6:17 pm
Posts: 278
There are some other options worth considering, though.

Related thread here.


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.