spring-framework / org.springframework.orm.jpa

Package org.springframework.orm.jpa

Types

DefaultJpaDialect

open class DefaultJpaDialect : JpaDialect, Serializable

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.

NOTE: Spring's JPA support requires JPA 2.1 or higher, as of Spring 5.0.

EntityManagerFactoryAccessor

abstract class EntityManagerFactoryAccessor : BeanFactoryAware

Base class for any class that needs to access a JPA EntityManagerFactory, usually in order to obtain a JPA EntityManager. Defines common properties.

EntityManagerHolder

open class EntityManagerHolder : ResourceHolderSupport

Holder wrapping a JPA EntityManager. JpaTransactionManager binds instances of this class to the thread, for a given EntityManagerFactory.

Note: This is an SPI class, not intended to be used by applications.

EntityManagerProxy

interface EntityManagerProxy : EntityManager

Subinterface of javax.persistence.EntityManager to be implemented by EntityManager proxies. Allows access to the underlying target EntityManager.

This interface is mainly intended for framework usage. Application code should prefer the use of the javax.persistence.EntityManager#getDelegate() method to access native functionality of the underlying resource.

ExtendedEntityManagerCreator

abstract class ExtendedEntityManagerCreator

Delegate for creating a variety of javax.persistence.EntityManager proxies that follow the JPA spec's semantics for "extended" EntityManagers.

Supports several different variants of "extended" EntityManagers: in particular, an "application-managed extended EntityManager", as defined by javax.persistence.EntityManagerFactory#createEntityManager(), as well as a "container-managed extended EntityManager", as defined by javax.persistence.PersistenceContextType#EXTENDED.

The original difference between "application-managed" and "container-managed" was the need for explicit joining of an externally managed transaction through the EntityManager#joinTransaction() method in the "application" case versus the automatic joining on each user-level EntityManager operation in the "container" case. As of JPA 2.1, both join modes are available with both kinds of EntityManagers, so the difference between "application-" and "container-managed" is now primarily in the join mode default and in the restricted lifecycle of a container-managed EntityManager (i.e. tied to the object that it is injected into).

JpaDialect

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.

LocalEntityManagerFactoryBean

open class LocalEntityManagerFactoryBean : AbstractEntityManagerFactoryBean

org.springframework.beans.factory.FactoryBean that creates a JPA javax.persistence.EntityManagerFactory according to JPA's standard standalone bootstrap contract. This is the simplest way to set up a shared JPA EntityManagerFactory in a Spring application context; the EntityManagerFactory can then be passed to JPA-based DAOs via dependency injection. Note that switching to a JNDI lookup or to a LocalContainerEntityManagerFactoryBean definition is just a matter of configuration!

Configuration settings are usually read from a META-INF/persistence.xml config file, residing in the class path, according to the JPA standalone bootstrap contract. Additionally, most JPA providers will require a special VM agent (specified on JVM startup) that allows them to instrument application classes. See the Java Persistence API specification and your provider documentation for setup details.

This EntityManagerFactory bootstrap is appropriate for standalone applications which solely use JPA for data access. If you want to set up your persistence provider for an external DataSource and/or for global transactions which span multiple resources, you will need to either deploy it into a full Java EE application server and access the deployed EntityManagerFactory via JNDI, or use Spring's LocalContainerEntityManagerFactoryBean with appropriate configuration for local setup according to JPA's container contract.

Note: This FactoryBean has limited configuration power in terms of what configuration it is able to pass to the JPA provider. If you need more flexible configuration, for example passing a Spring-managed JDBC DataSource to the JPA provider, consider using Spring's more powerful LocalContainerEntityManagerFactoryBean instead.

NOTE: Spring's JPA support requires JPA 2.1 or higher, as of Spring 5.0. JPA 1.0/2.0 based applications are still supported; however, a JPA 2.1 compliant persistence provider is needed at runtime.

SharedEntityManagerCreator

abstract class SharedEntityManagerCreator

Delegate for creating a shareable JPA javax.persistence.EntityManager reference for a given javax.persistence.EntityManagerFactory.

A shared EntityManager will behave just like an EntityManager fetched from an application server's JNDI environment, as defined by the JPA specification. It will delegate all calls to the current transactional EntityManager, if any; otherwise it will fall back to a newly created EntityManager per operation.

For a behavioral definition of such a shared transactional EntityManager, see javax.persistence.PersistenceContextType#TRANSACTION and its discussion in the JPA spec document. This is also the default being used for the annotation-based javax.persistence.PersistenceContext#type().

Exceptions

JpaObjectRetrievalFailureException

open class JpaObjectRetrievalFailureException : ObjectRetrievalFailureException

JPA-specific subclass of ObjectRetrievalFailureException. Converts JPA's EntityNotFoundException.

JpaOptimisticLockingFailureException

open class JpaOptimisticLockingFailureException : ObjectOptimisticLockingFailureException

JPA-specific subclass of ObjectOptimisticLockingFailureException. Converts JPA's OptimisticLockException.

JpaSystemException

open class JpaSystemException : UncategorizedDataAccessException

JPA-specific subclass of UncategorizedDataAccessException, for JPA system errors that do not match any concrete org.springframework.dao exceptions.