This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Object Relational Mapping and the fly likes Two phase commit in hibernate? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Two phase commit in hibernate?" Watch "Two phase commit in hibernate?" New topic
Author

Two phase commit in hibernate?

Brendon Woodford
Ranch Hand

Joined: Jan 22, 2010
Posts: 53
hi all ,
Could anybody tell me how 2phase commit is exercised in hibernate?

Thanks in advance
Brendon
Arun Kumarr
Ranch Hand

Joined: May 16, 2005
Posts: 513

2PC are not managed by hibernate inherently.
We need a JTA to do that. Hibernate can use a JTA to work on transaction management.
This link might give you some idea.


If you are not laughing at yourself, then you just didn't get the joke.
Brendon Woodford
Ranch Hand

Joined: Jan 22, 2010
Posts: 53
Thanks Arun for your reply,
The material that you referred to says that we can achieve 2phase commit for BMT(Bean managed transaction )and CMT (container managed transaction ) ie both involving ejb. Can't we reap the benefits of 2phase commit without using ejb ie can we write distributed transaction by using normal hibernate session and transaction in an application server?
Please answer to clear my doubt.
Brendon Woodford
Ranch Hand

Joined: Jan 22, 2010
Posts: 53
Thanks Arun for your reply,
The material that you referred to says that we can achieve 2phase commit for BMT(Bean managed transaction )and CMT (container managed transaction ) ie both involving ejb. Can't we reap the benefits of 2phase commit without using ejb ie can we write distributed transaction by using normal hibernate session and transaction in an application server?
Please answer to clear my doubt.

Thanks .
Brendon
Arun Kumarr
Ranch Hand

Joined: May 16, 2005
Posts: 513

Yes, you can.
Hibernate can participate in a distributed transaction outside/inside of the container (with or without EJB).
Check the second code snippet in the link I provided. It uses no EJB.
In fact you can use a stand-alone JTA implementation running inside the application server and hibernate can participate in it.
Brendon Woodford
Ranch Hand

Joined: Jan 22, 2010
Posts: 53
Thanks Arun for prompt reply
That means you are saying that when using distributed transaction without an application server(without ejb) for every distributed transaction I will have to use the
UserTransaction tx=(UserTransaction)new InitialContext().lookup("java:comp/UserTransaction");
tx.begin();
-----
-----
tx.commit();

Is it so?
If it is so then in a stand alone program without any application server who will do the job of a Transaction manager and who will do the job of a resource manager.I believe in a two phase commit both Transaction manager and resource manager play important part.

Please bear with me if my questions sound a little annoying. But they are my genuine doubts. I did not work on distributed transactions much. So your help is highly appreciated and valued.
Thanks Arun.


Brendon


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Two phase commit in hibernate?