File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Two phase commit in hibernate?

 
Brendon Woodford
Ranch Hand
Posts: 53
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all ,
Could anybody tell me how 2phase commit is exercised in hibernate?

Thanks in advance
Brendon
 
Arun Kumarr
Ranch Hand
Posts: 661
Eclipse IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Brendon Woodford
Ranch Hand
Posts: 53
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 53
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 661
Eclipse IDE Java Spring
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 53
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic