use JTA transaction or not?

newguy picture newguy · Jan 17, 2011 · Viewed 11.3k times · Source

I am developing a J2EE application which is deployed on JBoss application server. The application is composed of an EJB 2.x component and a web component and is running on local computer or remote server. The database is either Oracle or SQL Server and is not in a distributed envrionment.

I am using Hibernate 3.6 (JPA 2.0 implementation) for the transactions. Should I use JTA which is container managed transaction or is it overkilled to use it?

Currently I am using JTA and it turns out it is running fine but with some small issues which I do not know whether it is related to the transaction management or not. Will it be easier or more reliable to use local transaction management?

Answer

Arjan Tijms picture Arjan Tijms · Jan 22, 2011

JTA transactions are always recommended above other kinds of transaction APIs, especially if you are referring to the native transactions that are still part of the JPA API. Note that you can't say 'JTA vs resource local transactions', as JTA actually manages resource local transactions among others.

Gavin King (creator of Hibernate) once indicated in an interview that this JPA specific API was a mistake and that the much more flexible JTA API should be preferred. Especially when using declarative transactions, JTA is very lightweight. The word overkill would actually apply more to using the JPA native transaction API, then to using JTA.

There is something to say about the choice between using XA or resource local transactions with JTA. See my answer here for some more details about that: JTA or LOCAL transactions in JPA2+Hibernate 3.6.0?

I do wonder why you are using EJB 2 in combination with JPA 2.0. EJB 3.1 would be a much more logical choice here. EJB 2 is completely deprecated (will be pruned in Java EE 7).