We are migrating from Spring 3 to Spring 4 along with introducing EntityManager. Earlier in the code we had used OpenSessionInViewInterceptor
as interceptor in the bean with urlmapping. It was working fine by attaching a session to every thread request from web.
Now I am using OpenEntityManagerInViewInterceptor
but the EntityManager
is not attached to the current thread, and get the exception
No EntityManager with actual transaction available for current thread - cannot reliably process 'persist' call
If I put @Transactional
above my DAO method then it works fine, but I will have to do it in lot of places, so want to avoid it and trying to fix it with OpenEntityManagerInViewInterceptor
. Please let me know how can I get it working.
applicationContext.xml -
<bean id="openEntityManagerInViewInterceptor" class="org.springframework.orm.jpa.support.OpenEntityManagerInViewInterceptor">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
dispatcher-servlet.xml -
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/EditHelp/*.do">EditHelpController</prop>
</props>
</property>
<property name="interceptors">
<list>
<ref bean="openEntityManagerInViewInterceptor" />
</list>
</property>
</bean>
Any help would be appreciated. Thank you.