-->
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.  [ 5 posts ] 
Author Message
 Post subject: Need help about Transaction
PostPosted: Tue Apr 19, 2005 10:03 am 
Newbie

Joined: Mon Apr 18, 2005 9:07 am
Posts: 4
I want to use 2 functions with in each a transaction.

A() {
HibernateUtil.beginTransaction();
fctA();
HibernateUtil.commitTransaction();
}

B() {
HibernateUtil.beginTransaction();
fctB();
HibernateUtil.commitTransaction();
}

If I call A or B in a Session, no problem.
But if I call A and B in the same session, the commit in function B() commit the 2 transactions.

So I modified functions as follows:

A() {
HibernateUtil.currentTransaction();
fctA();
}

B() {
HibernateUtil. currentTransaction();
fctB();
}

Now, only one transaction is manipulated, but I don't known where to do the call to commit.
A and B are not transaction, because there are no commit in it.

http://www.dotnetguru.org/articles/doss ... apping.htm talk about a ServiceLocator to commit all transaction.

Thanks a lot for your answers.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 19, 2005 10:58 am 
Newbie

Joined: Wed Sep 22, 2004 10:20 am
Posts: 5
Location: Romania
You may want to check the Spring framework. That will give you the opportunity to use declarative transactions instead of separating them programatically.
Another solution is to have 2 different layers let's call them service and DAO. In services you would explicitly commit/rollback transactions while in DAO you will not have any transaction code. Passing the connection can be done with a ThreadLocal variable so as you do not polute the DAO code with Connection objects in each methods.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 19, 2005 11:15 am 
Newbie

Joined: Mon Apr 18, 2005 9:07 am
Posts: 4
Yes for Services and DAO, but normaly all Hibernate code is in DAO object.
And the transaction code is the DAO object, but commit too, and this is my problem.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 19, 2005 11:38 am 
Newbie

Joined: Mon Apr 18, 2005 9:07 am
Posts: 4
All transaction code isn't in the DAO.
I use a service to do the transaction.

Service {
executeTransaction() {
HibernateUtil.beginTransaction();
A();
B();
C();
HibernateUtil.commitTransaction();
}
}

But if in B function, user want to do a transaction, A and B are commited.
I want to commit just B.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 19, 2005 11:44 am 
Newbie

Joined: Wed Sep 22, 2004 10:20 am
Posts: 5
Location: Romania
The DAOs will not have any transaction code.
You will just have to add a new method in Service for each behaviour you have:

m0{
A();
B();
}

m1{
A()
}

m2{
B()
}

in begin/end of methods you will have to add the commit/rollback code.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.