Pergunta

I am working on a project that uses Spring's Hibernate OpenSessionInViewFilter and also the AOP version – OpenSessionInterceptor. The AOP interceptor is configured for Quartz jobs to provide the same convenience during a job's execution as during a web request.

Now, I am migrating this project from native Spring / Hibernate ORM to Spring JPA with Hibernate as the provider. Though there is an OpenEntityManagerInViewFilter provided by Spring ORM (which does basically the same thing as the Session Filter), there is no OpenEntityManagerInterceptor or anything similar. I am unable to figure out what is the best approach here, so the question is:

Should I write my own interceptor and/or fiddle with the SharedEntityManager classes, or is there another way?

Note: The project is now built with Spring 4.0, JPA 2.1 and Hibernate 4.3.

Foi útil?

Solução

Spring has an OpenEntityManagerInViewInterceptor as the JavaDoc suggests. If the scope of the EntityManager shall not be request bound, the usual approach is to build coarse grained components that get an @Transactional annotation as this will "bind" the EntityManager to the scope of the transaction.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top