Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What transaction manager to use? (JPA, Spring)

I'm developing a web application based on JPA + Hibernate, Spring and Wicket. I was wondering what's the best way of implementing transactions in my code? What transaction manager should I use? Should it be org.springframework.orm.jpa.JpaTransactionManager, or org.springframework.jdbc.datasource.DataSourceTransactionManager or something else? I'd like to use Spring for managing my transactions.

like image 269
John Manak Avatar asked Oct 07 '10 10:10

John Manak


People also ask

How does JPA manage transactions in Spring?

You only need to annotate your interface, class, or method with Spring's @Transactional annotation. Spring then wraps your service in a generated proxy that joins an active transaction or starts a new one and commits or rolls the transaction back after your method got executed.

What type of transaction management does Spring support?

Spring supports both programmatic and declarative transaction management. EJBs require an application server, but Spring transaction management can be implemented without the need of an application server.

What is JPA transaction manager?

This transaction manager is appropriate for applications that use a single JPA EntityManagerFactory for transactional data access. JTA (usually through JtaTransactionManager ) is necessary for accessing multiple transactional resources within the same transaction.

Which PlatformTransactionManager s Can you use with JPA?

nanda is right, you can only use JpaTransactionManager. The Transaction Manager abstraction we are talking about here is Spring's PlatformTransactionManager interface, and JPATransactionManager is the only implementation of that interface that understands JPA.


1 Answers

nanda is right, you can only use JpaTransactionManager. The Transaction Manager abstraction we are talking about here is Spring's PlatformTransactionManager interface, and JPATransactionManager is the only implementation of that interface that understands JPA.

You should read the chapter Transaction Management from the Spring reference to better understand this topic.

like image 64
Sean Patrick Floyd Avatar answered Oct 20 '22 00:10

Sean Patrick Floyd