-->
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: Logical transaction - commit
PostPosted: Mon May 05, 2008 6:15 am 
Newbie

Joined: Wed Apr 30, 2008 4:46 am
Posts: 8
Hibernate version:3.2.6

Name and version of the database you are using:Oracle 9

Hi,

I am new to hibernate. Please help me with the following problem.

i doing a logical transaction which involves more than two database operations i want to commit only if all the database operations have successfully executed. My code structure looks like..
//business class
sessionFactory.openSession();
dao1.method1();
dao2.method3()
//i actually want to do a commit here
session.close();

//data access classes
class DAO1{
method1(){
//1. begin transaction
//2. db operation
//3. commit transation
}
method2(){
}
}
class DAO2{
method3(){
}
..
methodn(){
}
}
currenly im calling commit in all the dao methods, but i want to commit only once after executing all the dao methods. How should i do it? is it possible to call commit in the business service class?

I read few documentation. But im not finding it easy to understand.

Thanks in advance.
Appreciate if someone can provide some code samples.

_________________
thanks,
windy

Well begun is half done.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 05, 2008 11:37 am 
Senior
Senior

Joined: Fri Jun 01, 2007 12:41 pm
Posts: 121
I have implemented nested transactions to handle transaction from business layer: implement business level transactions that span multiple data layers.

So here is how it works in my business layer:

MyBusinessController
Code:
openSession() as currentSession() using SessionContext
openTransaction()
dataController1.executeMethod()
dataController2.executeMethod()
commutTransaction()
rollbackTransaction() in case of exception


DataContrller1.executeMethod()
Code:
read currentSession
read transaction
  --if transaction is already open then use it, else open a new transaction
  --execute SQL statements
  --commit the transaction iff it is a new transaction opened here, else continue
flush the session


DataContrller2.executeMethod()
Code:
read currentSession
read transaction
  --if transaction is already open & active then use it, else open a new transaction
  --execute SQL statements
  --commit the transaction iff it is a new transaction opened here, else continue
flush the session


This way a new transaction is open in business layer and same is used in data layers. Let me know if you need sample code for this implementation.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 06, 2008 9:22 am 
Newbie

Joined: Wed Apr 30, 2008 4:46 am
Posts: 8
sjhyam wrote:
I have implemented nested transactions to handle transaction from business layer: implement business level transactions that span multiple data layers.

So here is how it works in my business layer:

MyBusinessController
Code:
openSession() as currentSession() using SessionContext
openTransaction()
dataController1.executeMethod()
dataController2.executeMethod()
commutTransaction()
rollbackTransaction() in case of exception


DataContrller1.executeMethod()
Code:
read currentSession
read transaction
  --if transaction is already open then use it, else open a new transaction
  --execute SQL statements
  --commit the transaction iff it is a new transaction opened here, else continue
flush the session


DataContrller2.executeMethod()
Code:
read currentSession
read transaction
  --if transaction is already open & active then use it, else open a new transaction
  --execute SQL statements
  --commit the transaction iff it is a new transaction opened here, else continue
flush the session


This way a new transaction is open in business layer and same is used in data layers. Let me know if you need sample code for this implementation.


Thanks dude! It really helped a lot. Please send me sample code. Thanks again

_________________
thanks,
windy

Well begun is half done.


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.