Top Description Constructors Methods
org.springframework.orm.jpa

public Class DefaultJpaDialect

extends Object
implements JpaDialect, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.springframework.orm.jpa.JpaDialect, org.springframework.dao.support.PersistenceExceptionTranslator
Known Direct Subclasses
org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect, org.springframework.orm.jpa.vendor.HibernateJpaDialect
Annotations
@SuppressWarnings:serial
Imports
java.io.Serializable, java.sql.SQLException, jakarta.persistence.EntityManager, .PersistenceException, org.springframework.dao.DataAccessException, org.springframework.jdbc.datasource.ConnectionHandle, org.springframework.lang.Nullable, org.springframework.transaction.InvalidIsolationLevelException, .TransactionDefinition, .TransactionException

Default implementation of the JpaDialect interface. Used as default dialect by JpaTransactionManager.

Simply begins a standard JPA transaction in beginTransaction and performs standard exception translation through EntityManagerFactoryUtils.

Author
Juergen Hoeller
Since
2.0
See Also
JpaTransactionManager#setJpaDialect

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Object
beginTransaction(EntityManager
the EntityManager to begin a JPA transaction on
entityManager
,
TransactionDefinition
the Spring transaction definition that defines semantics
definition
)

Implements org.springframework.orm.jpa.JpaDialect.beginTransaction.

This implementation invokes the standard JPA Transaction.begin method.
public void
cleanupTransaction(Object
arbitrary object that holds transaction data, if any (as returned by beginTransaction or prepareTransaction)
transactionData
)

Implements org.springframework.orm.jpa.JpaDialect.cleanupTransaction.

This implementation does nothing, since the default beginTransaction implementation does not require any cleanup.
public ConnectionHandle
getJdbcConnection(EntityManager
the current JPA EntityManager
entityManager
,
boolean
whether the Connection is only needed for read-only purposes
readOnly
)

Implements org.springframework.orm.jpa.JpaDialect.getJdbcConnection.

This implementation always returns null, indicating that no JDBC Connection can be provided.
public Object
prepareTransaction(EntityManager
the EntityManager to begin a JPA transaction on
entityManager
,
boolean
whether the transaction is supposed to be read-only
readOnly
,
String
the name of the transaction (if any)
name
)

Implements org.springframework.orm.jpa.JpaDialect.prepareTransaction.

Prepare a JPA transaction, applying the specified semantics.
public void
releaseJdbcConnection(ConnectionHandle
the JDBC Connection handle to release
conHandle
,
EntityManager
the current JPA EntityManager
em
)

Implements org.springframework.orm.jpa.JpaDialect.releaseJdbcConnection.

This implementation does nothing, assuming that the Connection will implicitly be closed with the EntityManager.
public DataAccessException
translateExceptionIfPossible(RuntimeException
a RuntimeException to translate
ex
)

Implements org.springframework.dao.support.PersistenceExceptionTranslator.translateExceptionIfPossible.

This implementation delegates to EntityManagerFactoryUtils.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

DefaultJpaDialectback to summary
public DefaultJpaDialect()

Method Detail

beginTransactionback to summary
public Object beginTransaction(EntityManager entityManager, TransactionDefinition definition) throws PersistenceException, SQLException, TransactionException

Implements org.springframework.orm.jpa.JpaDialect.beginTransaction.

This implementation invokes the standard JPA Transaction.begin method. Throws an InvalidIsolationLevelException if a non-default isolation level is set.

This implementation does not return any transaction data Object, since there is no state to be kept for a standard JPA transaction. Hence, subclasses do not have to care about the return value (null) of this implementation and are free to return their own transaction data Object.

Parameters
entityManager:EntityManager

Doc from org.springframework.orm.jpa.JpaDialect.beginTransaction.

the EntityManager to begin a JPA transaction on

definition:TransactionDefinition

Doc from org.springframework.orm.jpa.JpaDialect.beginTransaction.

the Spring transaction definition that defines semantics

Returns:Object

Doc from org.springframework.orm.jpa.JpaDialect.beginTransaction.

an arbitrary object that holds transaction data, if any (to be passed into cleanupTransaction). May implement the org.springframework.transaction.SavepointManager interface.

Annotations
@Override
@Nullable
Exceptions
PersistenceException:

Doc from org.springframework.orm.jpa.JpaDialect.beginTransaction.

if thrown by JPA methods

SQLException:

Doc from org.springframework.orm.jpa.JpaDialect.beginTransaction.

if thrown by JDBC methods

TransactionException:

Doc from org.springframework.orm.jpa.JpaDialect.beginTransaction.

in case of invalid arguments

See Also
jakarta.persistence.EntityTransaction#begin, org.springframework.transaction.InvalidIsolationLevelException, cleanupTransaction
cleanupTransactionback to summary
public void cleanupTransaction(Object transactionData)

Implements org.springframework.orm.jpa.JpaDialect.cleanupTransaction.

This implementation does nothing, since the default beginTransaction implementation does not require any cleanup.

Parameters
transactionData:Object

Doc from org.springframework.orm.jpa.JpaDialect.cleanupTransaction.

arbitrary object that holds transaction data, if any (as returned by beginTransaction or prepareTransaction)

Annotations
@Override
See Also
beginTransaction
getJdbcConnectionback to summary
public ConnectionHandle getJdbcConnection(EntityManager entityManager, boolean readOnly) throws PersistenceException, SQLException

Implements org.springframework.orm.jpa.JpaDialect.getJdbcConnection.

This implementation always returns null, indicating that no JDBC Connection can be provided.

Parameters
entityManager:EntityManager

Doc from org.springframework.orm.jpa.JpaDialect.getJdbcConnection.

the current JPA EntityManager

readOnly:boolean

Doc from org.springframework.orm.jpa.JpaDialect.getJdbcConnection.

whether the Connection is only needed for read-only purposes

Returns:ConnectionHandle

Doc from org.springframework.orm.jpa.JpaDialect.getJdbcConnection.

a handle for the Connection, to be passed into releaseJdbcConnection, or null if no JDBC Connection can be retrieved

Annotations
@Override
@Nullable
Exceptions
PersistenceException:

Doc from org.springframework.orm.jpa.JpaDialect.getJdbcConnection.

if thrown by JPA methods

SQLException:

Doc from org.springframework.orm.jpa.JpaDialect.getJdbcConnection.

if thrown by JDBC methods

prepareTransactionback to summary
public Object prepareTransaction(EntityManager entityManager, boolean readOnly, String name) throws PersistenceException

Implements org.springframework.orm.jpa.JpaDialect.prepareTransaction.

Doc from org.springframework.orm.jpa.JpaDialect.prepareTransaction.

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 cleanupTransaction.

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).

Parameters
entityManager:EntityManager

the EntityManager to begin a JPA transaction on

readOnly:boolean

whether the transaction is supposed to be read-only

name:String

the name of the transaction (if any)

Returns:Object

an arbitrary object that holds transaction data, if any (to be passed into cleanupTransaction)

Annotations
@Override
@Nullable
Exceptions
PersistenceException:
if thrown by JPA methods
releaseJdbcConnectionback to summary
public void releaseJdbcConnection(ConnectionHandle conHandle, EntityManager em) throws PersistenceException, SQLException

Implements org.springframework.orm.jpa.JpaDialect.releaseJdbcConnection.

This implementation does nothing, assuming that the Connection will implicitly be closed with the EntityManager.

If the JPA implementation returns a Connection handle that it expects the application to close after use, the dialect implementation needs to invoke Connection.close() (or some other method with similar effect) here.

Parameters
conHandle:ConnectionHandle

Doc from org.springframework.orm.jpa.JpaDialect.releaseJdbcConnection.

the JDBC Connection handle to release

em:EntityManager

Doc from org.springframework.orm.jpa.JpaDialect.releaseJdbcConnection.

the current JPA EntityManager

Annotations
@Override
Exceptions
PersistenceException:

Doc from org.springframework.orm.jpa.JpaDialect.releaseJdbcConnection.

if thrown by JPA methods

SQLException:

Doc from org.springframework.orm.jpa.JpaDialect.releaseJdbcConnection.

if thrown by JDBC methods

See Also
java.sql.Connection#close()
translateExceptionIfPossibleback to summary
public DataAccessException translateExceptionIfPossible(RuntimeException ex)

Implements org.springframework.dao.support.PersistenceExceptionTranslator.translateExceptionIfPossible.

This implementation delegates to EntityManagerFactoryUtils.

Parameters
ex:RuntimeException

Doc from org.springframework.dao.support.PersistenceExceptionTranslator.translateExceptionIfPossible.

a RuntimeException to translate

Returns:DataAccessException

Doc from org.springframework.dao.support.PersistenceExceptionTranslator.translateExceptionIfPossible.

the corresponding DataAccessException (or null if the exception could not be translated, as in this case it may result from user code rather than from an actual persistence problem)

Annotations
@Override
@Nullable
See Also
EntityManagerFactoryUtils#convertJpaAccessExceptionIfPossible