@PersistenceContext) and
AOP-driven exception translation through
PersistenceExceptionTranslationPostProcessor@Deprecated public class JpaInterceptor extends JpaAccessor implements MethodInterceptor
Application code must retrieve a JPA EntityManager via the
EntityManagerFactoryUtils.getEntityManager method or - preferably -
via a shared EntityManager reference, to be able to detect a
thread-bound EntityManager. Typically, the code will look like as follows:
public void doSomeDataAccessAction() {
this.entityManager...
}
Note that this interceptor automatically translates PersistenceExceptions,
via delegating to the EntityManagerFactoryUtils.convertJpaAccessException
method that converts them to exceptions that are compatible with the
org.springframework.dao exception hierarchy (like JpaTemplate does).
This class can be considered a declarative alternative to JpaTemplate's callback approach. The advantages are:
The drawback is the dependency on interceptor configuration. However, note that this interceptor is usually not necessary in scenarios where the data access code always executes within transactions. A transaction will always have a thread-bound EntityManager in the first place, so adding this interceptor to the configuration just adds value when fine-tuning EntityManager settings like the flush mode - or when relying on exception translation.
JpaTransactionManager,
JpaTemplatelogger| Constructor and Description |
|---|
JpaInterceptor()
Deprecated.
|
| Modifier and Type | Method and Description |
|---|---|
Object |
invoke(MethodInvocation methodInvocation)
Deprecated.
|
void |
setExceptionConversionEnabled(boolean exceptionConversionEnabled)
Deprecated.
Set whether to convert any PersistenceException raised to a Spring DataAccessException,
compatible with the
org.springframework.dao exception hierarchy. |
afterPropertiesSet, flushIfNecessary, getEntityManager, getJpaDialect, isFlushEager, setEntityManager, setFlushEager, setJpaDialect, translateIfNecessarycreateEntityManager, getEntityManagerFactory, getJpaPropertyMap, getPersistenceUnitName, getTransactionalEntityManager, setBeanFactory, setEntityManagerFactory, setJpaProperties, setJpaPropertyMap, setPersistenceUnitNamepublic void setExceptionConversionEnabled(boolean exceptionConversionEnabled)
org.springframework.dao exception hierarchy.
Default is "true". Turn this flag off to let the caller receive raw exceptions as-is, without any wrapping.
DataAccessExceptionpublic Object invoke(MethodInvocation methodInvocation) throws Throwable
invoke in interface MethodInterceptorThrowable