TransactionManager is completely different from EntityManager, one is responsible for entities (listener, entities, relationships, conservation life cycle, and this interface defines methods that are used to interact with the persistence context) related to a specific persistence context where objects are alive, while the TransactionManager is responsible for access to transactional data, providing support for the entire transaction that must occur in your application.
A configuration associates a single entitymanager with a specific transaction operator.
<bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory" /> <qualifier value="pagTransactionManager" /> </bean> <bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory"> <property name="persistenceUnitName" value="persistenceUnit" /> <property name="dataSource" ref="dataSource" /> <property name="jpaDialect"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" /> </property> </bean>
What does it mean to connect to the database, and entities are managed by EntityManager, but the object that opens a closed transaction at the service level using the @Transaction annotation is TransactionManager.
The javax.transaction.TransactionManager interface allows the application server to manage transaction boundaries on behalf of a managed application; this interface contains many methods that are used to manage them, such as: commit, pause, rollback.
Thus, basically, one of these objects, depending on what you are looking for, manage and work with entities, use the entitymanager, control the transactional state of your application yourself using a transaction operator.
source share