-->
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: Does Hibernate support nested transactions
PostPosted: Tue Mar 30, 2004 6:31 am 
Beginner
Beginner

Joined: Sun Mar 28, 2004 9:01 am
Posts: 21
Hi,

I did not find out wheter hibernate supports nested transactions. We have a global transaction where we want to nest other transactions.

In detail we have a form object, that has multiple pages, whereas pages have multiple blocks.

So our idea is to have a global transaction around the form object. If choosing a page within the form we want to nest all changes within the page into another (nested) transaction. If the user then chooses a block within that page we again want to nest those changes into a (nested)transaction.

Is that possible using hibernate?

thx for help!
Rene


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 30, 2004 6:35 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Hibernate uses JDBC (or JTA) transactions, they can not be nested. What you need is an "application transaction" that spans multiple database transactions. Have a look at optimistic concurrency control and automatic version checking in the documentation.

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


Top
 Profile  
 
 Post subject: Re: Does Hibernate support nested transactions
PostPosted: Tue Aug 11, 2009 4:34 am 
Newbie

Joined: Tue Aug 11, 2009 4:21 am
Posts: 1
While Hibernate does not explicitly support nested transactions, using a JDBC 3.0 driver that is able to create savepoints can achieve this.

Create a Connection at the start of the program when the SessionFactory is created. At this point you also create a Savepoint that serves as the starting point for the transaction.

Then you move through each nested transaction. For each nested transaction, you should create another different savePoint i.e. a rollingSavePoint which you can rollback to should that nested transaction fail. Then for that same nested transaction, open a session that uses the Connection you created at the start (i.e. Session nestedTransaction = SessionFactory.openSession(connection)) and make your updates. Flush the session and close it.

After all nested transactions are completed, call connection.commit() to commit the global transaction and close it. Close the sessionFactory as per usual and continue to do whatever else you need to do.

Some things to note:
* Obviously autoCommit mode must be off, otherwise each time you call flush you'll be commiting straight to the DB.
* If you're also doing searching or other operations you'll want to open other sessions that use their own connections. Ensure that you set the Transaction isolation level to READ_UNCOMMITED or else you'll probably be facing locking problems.
* Of course you should commit periodically or else your database will have issues, or you can increase the size of database virtual memory.


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.