aspose file tools
The moose likes Object Relational Mapping and the fly likes Two phase commit in hibernate? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Reply 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: 508

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: 508

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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Two phase commit in hibernate?
 
Similar Threads
Database Refresh Issue(Save and query)
When is exclusive lock released
Update/Insert optimization in hibernate
disabling autoCommit in hibernate
Spring: partly commited Txn issue