Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

which transaction manager should I use (JTA vs JPA)?

Tags:

spring

jpa

jta

I have spring 4 application. At the moment I use JpatransactionManager.

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

Could you tell me how to choose transaction managers?

For instance, when should I use jta transaction manager and when jpa, and what benefit and disadvantages does they have?

And Is I know I have 2 way to work in Spring. First is JPA way and the second Hibernate way. first one includes java standard annotations and standard api and the second is hibenrate implementation. If i need to use JTA, I must use hibernate and not JPA, does not it?

like image 973
grep Avatar asked Oct 21 '14 08:10

grep


People also ask

Which transaction manager implementation would be most appropriate?

In this model, Spring uses AOP over the transactional methods to provide data integrity. This is the preferred approach and works in most of the cases. Support for most of the transaction APIs such as JDBC, Hibernate, JPA, JDO, JTA etc. All we need to do is use proper transaction manager implementation class.

What is the difference between JTA and JPA?

JPA (Java Persistence API) is the Java ORM standard/specification for storing, accessing, and managing Java objects in a relational database. Hibernate is an implementation of the Java Persistence API (JPA) specification. JTA (Java Transaction API) is the Java standard/specification for distributed transactions.

Which transaction manager is appropriate for JEE application server?

The JTA UserTransaction and JDBC's transactional support are both available to J2EE application components.

What is JTA transaction manager?

The JTA specifies standard Java interfaces between a transaction manager and the parties involved in a distributed transaction system: the application, the application server, and the resource manager that controls access to the shared resources affected by the transactions.


1 Answers

If you want to delegate managed transactions to your Application Server and handle complex transactions across multiple resources you need to use the JtaTransactionManager, but I believe it is not needed in most cases. Read this for more information http://docs.spring.io/spring-framework/docs/4.0.x/spring-framework-reference/html/transaction.html

Do you need an application server for transaction management?

The Spring Framework’s transaction management support changes traditional rules as to when an enterprise Java application requires an application server.

In particular, you do not need an application server simply for declarative transactions through EJBs. In fact, even if your application server has powerful JTA capabilities, you may decide that the Spring Framework’s declarative transactions offer more power and a more productive programming model than EJB CMT.

Typically you need an application server’s JTA capability only if your application needs to handle transactions across multiple resources, which is not a requirement for many applications. Many high-end applications use a single, highly scalable database (such as Oracle RAC) instead. Standalone transaction managers such as Atomikos Transactions and JOTM are other options. Of course, you may need other application server capabilities such as Java Message Service (JMS) and Java EE Connector Architecture (JCA).

The Spring Framework gives you the choice of when to scale your application to a fully loaded application server. Gone are the days when the only alternative to using EJB CMT or JTA was to write code with local transactions such as those on JDBC connections, and face a hefty rework if you need that code to run within global, container-managed transactions. With the Spring Framework, only some of the bean definitions in your configuration file, rather than your code, need to change.

like image 97
Georgy Gobozov Avatar answered Oct 17 '22 03:10

Georgy Gobozov