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: Multiple save(object) in single transaction
PostPosted: Tue Jun 30, 2009 12:57 pm 
Newbie

Joined: Tue Jun 30, 2009 12:06 pm
Posts: 2
Dear All,
I am new to hibernate. Please help me regarding the multiple save object within single transaction.
try {
Transaction tx = session.beginTransaction();
session.save(emp);
session.save(dept);
tx.commit;
} catch (Exception e) {
tx.rollback;
}

Above code is saving "emp" and "dept" object in single transaction. If "session.save(emp)" is executed properly but "session.save(dept)" given error, while executing "tx.commit".

My question is, if "emp" and "dept" is saving within single transaction then either both has to commit or rollback, but "emp" is committed and "dept" came out with error.

Is there any way to commit or rollback both object within single transaction.

Thanks and regards.


Top
 Profile  
 
 Post subject: Re: Multiple save(object) in single transaction
PostPosted: Wed Jul 01, 2009 9:03 am 
Regular
Regular

Joined: Sun Sep 30, 2007 7:51 pm
Posts: 93
Just a guess, but don't you have somehow autocommit turned on? Because normally it should work as you would await.
Or maybe you have observed the changes with read/uncommited issolation level on database.


Top
 Profile  
 
 Post subject: Re: Multiple save(object) in single transaction
PostPosted: Wed Jul 01, 2009 11:17 am 
Newbie

Joined: Tue Jun 30, 2009 12:06 pm
Posts: 2
Thanks for the reply.

In cfg.xml file properties is set to autocommit=false
--------------
<property name="hibernate.connection.autocommit">false</property>

Oracle is also set as autocommit = Off
----------------------
Connected to:
Oracle Database 10g Release 10.2.0.1.0 - Production

SQL> show autocommit
autocommit OFF
SQL>


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.