interface JpaDialect : PersistenceExceptionTranslator
SPI strategy that encapsulates certain functionality that standard JPA 2.1 does not offer, such as access to the underlying JDBC Connection. This strategy is mainly intended for standalone usage of a JPA provider; most of its functionality is not relevant when running with JTA transactions.
In general, it is recommended to derive from DefaultJpaDialect instead of implementing this interface directly. This allows for inheriting common behavior (present and future) from DefaultJpaDialect, only overriding specific hooks to plug in concrete vendor-specific behavior.
Author
Juergen Hoeller
Author
Rod Johnson
Since
2.0
See Also
DefaultJpaDialectJpaTransactionManager#setJpaDialectJpaVendorAdapter#getJpaDialect()AbstractEntityManagerFactoryBean#setJpaDialectAbstractEntityManagerFactoryBean#setJpaVendorAdapter
abstract fun beginTransaction(entityManager: EntityManager, definition: TransactionDefinition): Any
Begin the given JPA transaction, applying the semantics specified by the given Spring transaction definition (in particular, an isolation level and a timeout). Called by JpaTransactionManager on transaction begin. An implementation can configure the JPA Transaction object and then invoke An implementation can apply the read-only flag as flush mode. In that case, a transaction data object can be returned that holds the previous flush mode (and possibly other data), to be reset in Implementations can also use the Spring transaction name, as exposed by the passed-in TransactionDefinition, to optimize for specific data access use cases (effectively using the current transaction name as use case identifier). This method also allows for exposing savepoint capabilities if supported by the persistence provider, through returning an Object that implements Spring's org.springframework.transaction.SavepointManager interface. JpaTransactionManager will use this capability if needed. |
|
abstract fun cleanupTransaction(transactionData: Any): Unit
Clean up the transaction via the given transaction data. Called by JpaTransactionManager and EntityManagerFactoryUtils on transaction cleanup. An implementation can, for example, reset read-only flag and isolation level of the underlying JDBC Connection. Furthermore, an exposed data access use case can be reset here. |
|
abstract fun getJdbcConnection(entityManager: EntityManager, readOnly: Boolean): ConnectionHandle
Retrieve the JDBC Connection that the given JPA EntityManager uses underneath, if accessing a relational database. This method will just get invoked if actually needing access to the underlying JDBC Connection, usually within an active JPA transaction (for example, by JpaTransactionManager). The returned handle will be passed into the This strategy is necessary as JPA does not provide a standard way to retrieve the underlying JDBC Connection (due to the fact that a JPA implementation might not work with a relational database at all). Implementations are encouraged to return an unwrapped Connection object, i.e. the Connection as they got it from the connection pool. This makes it easier for application code to get at the underlying native JDBC Connection, like an OracleConnection, which is sometimes necessary for LOB handling etc. We assume that calling code knows how to properly handle the returned Connection object. In a simple case where the returned Connection will be auto-closed with the EntityManager or can be released via the Connection object itself, an implementation can return a SimpleConnectionHandle that just contains the Connection. If some other object is needed in |
|
abstract fun prepareTransaction(entityManager: EntityManager, readOnly: Boolean, name: String): Any
Prepare a JPA transaction, applying the specified semantics. Called by EntityManagerFactoryUtils when enlisting an EntityManager in a JTA transaction or a locally joined transaction (e.g. after upgrading an unsynchronized EntityManager to a synchronized one). An implementation can apply the read-only flag as flush mode. In that case, a transaction data object can be returned that holds the previous flush mode (and possibly other data), to be reset in Implementations can also use the Spring transaction name to optimize for specific data access use cases (effectively using the current transaction name as use case identifier). |
|
abstract fun releaseJdbcConnection(conHandle: ConnectionHandle, entityManager: EntityManager): Unit
Release the given JDBC Connection, which has originally been retrieved via An implementation might simply do nothing, if the Connection returned by |
open class DefaultJpaDialect : JpaDialect, Serializable
Default implementation of the JpaDialect interface. Used as default dialect by JpaTransactionManager. Simply begins a standard JPA transaction in NOTE: Spring's JPA support requires JPA 2.1 or higher, as of Spring 5.0. |