What is the main objective to use JTA in a web application with Hibernate and Spring ?
Asked
Active
Viewed 701 times
1 Answers
2
The main one would be to have support for distributed transactions. For example, you might want to write to the database and send a JMS message, and have both part of the same transaction. Or to modify two different databases.
Another reason might be that you already run your app inside a Java EE container, providing support for JTA, and want to benefit from the container services (diagnostics, statistics, etc.).

Arjan Tijms
- 37,782
- 12
- 108
- 140

JB Nizet
- 678,734
- 91
- 1,224
- 1,255
-
1Okey Thank you , would you please explain the part of diagnostics and statistics , it's also possible will Hibernate ? – Angelika Mar 09 '13 at 21:08
-
2Your app server could provide a console application whilh, for example, lists all the current transactions, shows how many commits and rollbacks have been executed, point to the longest transactions, etc. It can do that because it controls its own transaction manager and can thus gathers those information from it. If you don't use its transaction manager, you'll lose that. – JB Nizet Mar 09 '13 at 21:12
-
Ok thnx , so JTA is close to server side ? – Angelika Mar 09 '13 at 21:18
-
1I don't understand what you mean by that. JTA is only a specification. This specification, and the transaction manager it defines, are provided by the application server. – JB Nizet Mar 09 '13 at 21:19
-
If I use only Hibernate is it possible to do all transactions without using JTA ? – Angelika Mar 09 '13 at 21:31
-
1Yes. [Hibernate](http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html_single/#transactions-demarcation) has transactions. And [Spring has declarative transactions](http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/htmlsingle/spring-framework-reference.html#transaction) (using Hibernate transactions). – JB Nizet Mar 09 '13 at 21:34