logixplayer
Newbie
Joined: 08/30/2009 13:12:33
Messages: 1
Offline
|
Hi people,
I am still battling this LazyInitializationException using JPA+Spring+Hibernate.
I have followed suggestions such as
1) move the filter definition for OpenEntityManagerInViewFilter to the top of the web.xml file so to be the first filter to intercept calls
2)Observe log files to see if the OpenEntityManagerInViewFilter is firing. It looks like it is:
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.logixplayer.pf.domain.Category.topics, no session or session was closed
org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:35
org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350)
org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:343)
org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:163)
com.logixplayer.pf.category.controller.CategoryController.onSubmit(CategoryController.java:3
org.springframework.web.servlet.mvc.SimpleFormController.onSubmit(SimpleFormController.java:409)
org.springframework.web.servlet.mvc.SimpleFormController.onSubmit(SimpleFormController.java:381)
org.springframework.web.servlet.mvc.SimpleFormController.processFormSubmission(SimpleFormController.java:267)
org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:265)
org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:4
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:511)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:112)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
I am missing something but I do not know what!
I know why I am getting the exception as I stated in my earlier post. The session is being closed when I try to access children (topics) of each category (parent). This is why I was trying to use OpenEntityManagerInViewFilter in the first place (to keep the jpa/hibernate session open so I can fetch the lazy topics (children of categories)
My only hunch is that the sessions are not unique but distinct. I.e. the session that is being used to get Categories is not being kept open for some reason.
In my web.xml, I declare this:
listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
<!-- classpath:applicationContext.xml -->
<!-- classpath:/data-access-context.xml -->
classpath:data-access-context.xml
</param-value>
</context-param>
which references my entityManagerFactory like so:
data-access-context.xml:
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="dataAccessPU" />
</bean>
<bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory"
ref="entityManagerFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />
The only thing that jumps out at me is the class definition for OpenEntityManagerInViewFilter:
Servlet 2.3 Filter 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.
Servlet 2.3???
I am using Servlet 2.5 and JSP 2.1.
Does OpenEntityManagerInViewFilter not work for servlet 2.5 specs??
I am totally stumped
Anyone can lend some help? Please do...I have been stuck for a very long time
Thanks so much!!
p.s.
the point of this exercise is to actually not take a performance hit.
There will be potentially thousands of users at one single time, I cannot afford to load EAGER. because then each user will have the same categories and the same topics in memory.
I need to figure out how to load lazy.
I have searched thoroughly on the net but cannot find a solution to this problem, even though it is quite a common issue.
I thought the OpenEntityManagerInViewFilter needed to be simply plugged in...
I really need some help on this one...please reach out...
thanks again
reference:
http://forum.springsource.org/showthread.php?t=76488
|