{@link org.springframework.transaction.PlatformTransactionManager} implementationfor a single JPA {@link javax.persistence.EntityManagerFactory}. Binds a JPA EntityManager from the specified factory to the thread, potentially allowing for one thread-bound EntityManager per factory. {@link SharedEntityManagerCreator}and {@link JpaTemplate} are aware of thread-bound entity managers and participatein such transactions automatically. Using either is required for JPA access code supporting this transaction management mechanism.
This transaction manager is appropriate for applications that use a single JPA EntityManagerFactory for transactional data access. JTA (usually through {@link org.springframework.transaction.jta.JtaTransactionManager}) is necessary for accessing multiple transactional resources within the same transaction. Note that you need to configure your JPA provider accordingly in order to make it participate in JTA transactions.
This transaction manager also supports direct DataSource access within a transaction (i.e. plain JDBC code working with the same DataSource). This allows for mixing services which access JPA and services which use plain JDBC (without being aware of JPA)! Application code needs to stick to the same simple Connection lookup pattern as with {@link org.springframework.jdbc.datasource.DataSourceTransactionManager}(i.e. {@link org.springframework.jdbc.datasource.DataSourceUtils#getConnection}or going through a {@link org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy}). Note that this requires a vendor-specific {@link JpaDialect} to be configured.
Note: To be able to register a DataSource's Connection for plain JDBC code, this instance needs to be aware of the DataSource ( {@link #setDataSource}). The given DataSource should obviously match the one used by the given EntityManagerFactory. This transaction manager will autodetect the DataSource used as known connection factory of the EntityManagerFactory, so you usually don't need to explicitly specify the "dataSource" property.
On JDBC 3.0, this transaction manager supports nested transactions via JDBC 3.0 Savepoints. The {@link #setNestedTransactionAllowed} "nestedTransactionAllowed"}flag defaults to "false", though, as nested transactions will just apply to the JDBC Connection, not to the JPA EntityManager and its cached objects. You can manually set the flag to "true" if you want to use nested transactions for JDBC access code which participates in JPA transactions (provided that your JDBC driver supports Savepoints). Note that JPA itself does not support nested transactions! Hence, do not expect JPA access code to semantically participate in a nested transaction.
@author Juergen Hoeller
@since 2.0
@see #setEntityManagerFactory
@see #setDataSource
@see LocalEntityManagerFactoryBean
@see JpaTemplate#execute
@see org.springframework.orm.jpa.support.SharedEntityManagerBean
@see org.springframework.jdbc.datasource.DataSourceUtils#getConnection
@see org.springframework.jdbc.datasource.DataSourceUtils#releaseConnection
@see org.springframework.jdbc.core.JdbcTemplate
@see org.springframework.jdbc.datasource.DataSourceTransactionManager
@see org.springframework.transaction.jta.JtaTransactionManager