spring - LazyInitializationException even with OpenEntityManagerInViewFilter -


i trying use openentitymanageinviewfilter, keep having lazyinitializationexception. people had similar problems when having entitymanager initialized twice - seems not case. in exception log can see, filter correctly firing.

web.xml:

<web-app version="2.4"     xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"     xsi:schemalocation="         http://java.sun.com/xml/ns/j2ee         http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">      <servlet>         <servlet-name>web-application</servlet-name>         <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class>         <load-on-startup>1</load-on-startup>     </servlet>      <servlet-mapping>         <servlet-name>web-application</servlet-name>         <url-pattern>/*</url-pattern>     </servlet-mapping>      <context-param>         <param-name>contextconfiglocation</param-name>         <param-value>web-inf/web-application-servlet.xml</param-value>     </context-param>      <listener>         <listener-class>org.springframework.web.context.contextloaderlistener</listener-class>     </listener>      <filter>         <filter-name>openentitymanageinviewfilter</filter-name>         <filter-class>org.springframework.orm.jpa.support.openentitymanagerinviewfilter</filter-class>     </filter>      <filter-mapping>         <filter-name>openentitymanageinviewfilter</filter-name>         <url-pattern>/*</url-pattern>     </filter-mapping>  </web-app> 

web-application-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans"        xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"        xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"        xsi:schemalocation="http://www.springframework.org/schema/beans             http://www.springframework.org/schema/beans/spring-beans-2.5.xsd             http://www.springframework.org/schema/context             http://www.springframework.org/schema/context/spring-context-3.1.xsd             http://www.springframework.org/schema/tx             http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">      <import resource="classpath:applicationcontext.xml"/>     <context:property-placeholder location="classpath:application.properties"/>      <bean id="viewresolver" class="org.springframework.web.servlet.view.freemarker.freemarkerviewresolver">         <property name="viewnames" value="*" />         <property name="cache" value="false"/>         <property name="prefix" value=""/>         <property name="suffix" value=".ftl"/>         <property name="exposespringmacrohelpers" value="false"/>     </bean>      <bean id="handleradapter" autowire="bytype" class="org.maite.controller.router.handleradapter" />     <bean id="handlermapping" autowire="bytype" class="org.maite.controller.router.handlermapping" /> </beans> 

applicationcontext.xml

<beans xmlns="http://www.springframework.org/schema/beans"        xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"        xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"        xsi:schemalocation="http://www.springframework.org/schema/beans             http://www.springframework.org/schema/beans/spring-beans-2.5.xsd             http://www.springframework.org/schema/context             http://www.springframework.org/schema/context/spring-context-3.1.xsd             http://www.springframework.org/schema/tx             http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">       <tx:annotation-driven />     <context:annotation-config/>     <context:spring-configured/>      <bean id="entitymanagerfactory"           class="org.springframework.orm.jpa.localcontainerentitymanagerfactorybean">         <property name="persistenceunitname" value="persistenceunit"/>     </bean>      <bean class="org.springframework.orm.jpa.support.persistenceannotationbeanpostprocessor" /> </beans> 

and exception (you can see openentitymanagerinview takes part of stack trace):

org.springframework.web.util.nestedservletexception: request processing failed; nested exception org.hibernate.lazyinitializationexception: failed lazily initialize collection of role: org.goout.model.event.schedule, no session or session closed     org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:894)     org.springframework.web.servlet.frameworkservlet.doget(frameworkservlet.java:778)     javax.servlet.http.httpservlet.service(httpservlet.java:621)     javax.servlet.http.httpservlet.service(httpservlet.java:722)     org.springframework.orm.jpa.support.openentitymanagerinviewfilter.dofilterinternal(openentitymanagerinviewfilter.java:147)     org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:76) root cause  org.hibernate.lazyinitializationexception: failed lazily initialize collection of role: org.goout.model.event.schedule, no session or session closed     org.hibernate.collection.internal.abstractpersistentcollection.throwlazyinitializationexception(abstractpersistentcollection.java:393)     org.hibernate.collection.internal.abstractpersistentcollection.throwlazyinitializationexceptionifnotconnected(abstractpersistentcollection.java:385)     org.hibernate.collection.internal.abstractpersistentcollection.initialize(abstractpersistentcollection.java:378)     org.hibernate.collection.internal.abstractpersistentcollection.read(abstractpersistentcollection.java:112)     org.hibernate.collection.internal.persistentset.toarray(persistentset.java:188)     java.util.arraylist.<init>(arraylist.java:151)     freemarker.template.simplesequence.<init>(simplesequence.java:162)     freemarker.template.defaultobjectwrapper.wrap(defaultobjectwrapper.java:117)     freemarker.template.wrappingtemplatemodel.wrap(wrappingtemplatemodel.java:134)     freemarker.template.simplehash.get(simplehash.java:224)     freemarker.core.dot._getastemplatemodel(dot.java:76)     freemarker.core.expression.getastemplatemodel(expression.java:89)     freemarker.core.iteratorblock.accept(iteratorblock.java:94)     freemarker.core.environment.visit(environment.java:221)     freemarker.core.mixedcontent.accept(mixedcontent.java:92)     freemarker.core.environment.visit(environment.java:221)     freemarker.core.environment.visit(environment.java:310)     freemarker.core.blockassignment.accept(blockassignment.java:83)     freemarker.core.environment.visit(environment.java:221)     freemarker.core.mixedcontent.accept(mixedcontent.java:92)     freemarker.core.environment.visit(environment.java:221)     freemarker.core.environment.process(environment.java:199)     freemarker.template.template.process(template.java:237)     org.springframework.web.servlet.view.freemarker.freemarkerview.processtemplate(freemarkerview.java:366)     org.springframework.web.servlet.view.freemarker.freemarkerview.dorender(freemarkerview.java:283)     org.springframework.web.servlet.view.freemarker.freemarkerview.rendermergedtemplatemodel(freemarkerview.java:233)     org.springframework.web.servlet.view.abstracttemplateview.rendermergedoutputmodel(abstracttemplateview.java:167)     org.springframework.web.servlet.view.abstractview.render(abstractview.java:262)     org.maite.dispatcherservlet.doservice(dispatcherservlet.java:38)     org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:882)     org.springframework.web.servlet.frameworkservlet.doget(frameworkservlet.java:778)     javax.servlet.http.httpservlet.service(httpservlet.java:621)     javax.servlet.http.httpservlet.service(httpservlet.java:722)     org.springframework.orm.jpa.support.openentitymanagerinviewfilter.dofilterinternal(openentitymanagerinviewfilter.java:147)     org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:76) 

you have same problem described in this question, means have 2 entitymanager beans - causing confusion.

basically need remove the

<import resource="classpath:applicationcontext.xml"/> 

from web-application-context.ml, partition beans such web-tier , application beans in separate context files , make sure component scan in each picks correct beans. might require moving classes different packages, difficult advise without more information structure of project.

finally reference both contexts web.xml


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -