Package org.springframework.orm.jpa.support

# Class OpenEntityManagerInViewInterceptor

java.lang.Object
org.springframework.orm.jpa.EntityManagerFactoryAccessor
org.springframework.orm.jpa.support.OpenEntityManagerInViewInterceptor

All Implemented Interfaces:
  `org.springframework.beans.factory.Aware`, `org.springframework.beans.factory.BeanFactoryAware`, `org.springframework.web.context.request.AsyncWebRequestInterceptor`, `org.springframework.web.context.request.WebRequestInterceptor`

public class OpenEntityManagerInViewInterceptor extends EntityManagerFactoryAccessor implements org.springframework.web.context.request.AsyncWebRequestInterceptor
Spring web request interceptor that binds a JPA EntityManager to the thread for the entire processing of the request. Intended for the "Open EntityManager in View" pattern, i.e. to allow for lazy loading in web views despite the original transactions already being completed.

This interceptor makes JPA EntityManagers available via the current thread, which will be autodetected by transaction managers. It is suitable for service layer transactions via `JpaTransactionManager` or `JtaTransactionManager` as well as for non-transactional read-only execution.

In contrast to `OpenEntityManagerInViewFilter`, this interceptor is set up in a Spring application context and can thus take advantage of bean wiring.

Since:
  2.0
Author:
  Juergen Hoeller
See Also:
  - `OpenEntityManagerInViewFilter`
  - `JpaTransactionManager`
  - `SharedEntityManagerCreator`
  - `TransactionSynchronizationManager`

## Field Summary

Fields
Modifier and Type
Field
Description
`static final String`
`PARTICIPATE_SUFFIX`
Suffix that gets appended to the EntityManagerFactory toString representation for the "participate in existing entity manager handling" request attribute.

### Fields inherited from class org.springframework.orm.jpa.EntityManagerFactoryAccessor

`logger`

## Constructor Summary

Constructors
Constructor
Description
`OpenEntityManagerInViewInterceptor()`

## Method Summary

Modifier and Type
Method
Description
`void`
`afterCompletion(org.springframework.web.context.request.WebRequest request, Exception ex)`
`void`
`afterConcurrentHandlingStarted(org.springframework.web.context.request.WebRequest request)`
`protected String`
`getParticipateAttributeName()`
Return the name of the request attribute that identifies that a request is already filtered.
`void`
`postHandle(org.springframework.web.context.request.WebRequest request, org.springframework.ui.ModelMap model)`
`void`
`preHandle(org.springframework.web.context.request.WebRequest request)`

### Methods inherited from class org.springframework.orm.jpa.EntityManagerFactoryAccessor

`createEntityManager, getEntityManagerFactory, getJpaPropertyMap, getPersistenceUnitName, getTransactionalEntityManager, obtainEntityManagerFactory, setBeanFactory, setEntityManagerFactory, setJpaProperties, setJpaPropertyMap, setPersistenceUnitName`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### PARTICIPATE_SUFFIX

public static final String PARTICIPATE_SUFFIX
Suffix that gets appended to the EntityManagerFactory toString representation for the "participate in existing entity manager handling" request attribute.

See Also:
  - `getParticipateAttributeName()`
  - Constant Field Values

## Constructor Details

### OpenEntityManagerInViewInterceptor

public OpenEntityManagerInViewInterceptor()

## Method Details

### preHandle

public void preHandle(org.springframework.web.context.request.WebRequest request) throws org.springframework.dao.DataAccessException

Specified by:
  `preHandle` in interface `org.springframework.web.context.request.WebRequestInterceptor`
Throws:
  `org.springframework.dao.DataAccessException`

### postHandle

public void postHandle(org.springframework.web.context.request.WebRequest request, @Nullable org.springframework.ui.ModelMap model)

Specified by:
  `postHandle` in interface `org.springframework.web.context.request.WebRequestInterceptor`

### afterCompletion

public void afterCompletion(org.springframework.web.context.request.WebRequest request, @Nullable Exception ex) throws org.springframework.dao.DataAccessException

Specified by:
  `afterCompletion` in interface `org.springframework.web.context.request.WebRequestInterceptor`
Throws:
  `org.springframework.dao.DataAccessException`

### afterConcurrentHandlingStarted

public void afterConcurrentHandlingStarted(org.springframework.web.context.request.WebRequest request)

Specified by:
  `afterConcurrentHandlingStarted` in interface `org.springframework.web.context.request.AsyncWebRequestInterceptor`

### getParticipateAttributeName

protected String getParticipateAttributeName()
Return the name of the request attribute that identifies that a request is already filtered. Default implementation takes the toString representation of the EntityManagerFactory instance and appends ".FILTERED".

See Also:
  - `PARTICIPATE_SUFFIX`