Results 1 to 1 of 1
- 08-29-2009, 07:32 PM #1
Member
- Join Date
- Aug 2009
- Posts
- 1
- Rep Power
- 0
LazyInitializationException Hibernate + JPA + Spring Help!!!
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:
I am missing something but I do not know what!Java Code: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:358) 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:38) 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:48) 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 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.
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:Java Code:public ModelAndView onSubmit(Object command) throws ServletException { //new ModelAndView(new RedirectView(getSuccessView())); //return new ModelAndView("profile/form","profile1","profile2"); CategoryBean categoryBean = (CategoryBean) command; System.out.println("the name from the command bean is: "+categoryBean.getName()); // call category service //iCategoryService ICategoryService categoryService = (ICategoryService)DataAccessServiceFactory.getBean("iCategoryService"); List<Category> categories = categoryService.findByName("Autos", null); for (Category category : categories) { System.out.println("category: "+category.getName()); System.out.println("****now to get topics if there are any!****"); Set<Topic> topics = category.getTopics(); [B]<------ Point where I get Lazy Exception!!![/B] for (Topic topic : topics) { System.out.println("topic: "+topic.getTitle()); System.out.println("****now to get submissions if there are any!****"); Set<Submission> submissions = topic.getSubmissions(); for (Submission submission : submissions) { System.out.println("submission topic: " +submission.getTopic()); System.out.println("submission title: " +submission.getTitle()); } } } return new ModelAndView("registration/registration","profile1","profile2");
which references my entityManagerFactory like so:Java Code:<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>
data-access-context.xml:
The only thing that jumps out at me is the class definition for OpenEntityManagerInViewFilter:Java Code:<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" />
Servlet 2.3???Java Code: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.
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!!
Similar Threads
-
Java Application Architecture for Struts, Spring and Hibernate
By stujava in forum Advanced JavaReplies: 0Last Post: 08-20-2009, 07:39 AM -
Hibernate, Spring developers seeked at GBIF, Copenhagen
By m.doering in forum Jobs OfferedReplies: 0Last Post: 07-23-2008, 03:07 PM -
Foreign Exchange NYC- Core Java, JMS, Hibernate, Spring Developer
By evanp in forum Jobs OfferedReplies: 0Last Post: 07-22-2008, 04:36 PM -
Lead Java developer -- Spring and Hibernate experience
By orjueladiego in forum Jobs OfferedReplies: 0Last Post: 10-29-2007, 01:50 PM -
Log4J, problem with Hibernate and Spring
By Marcus in forum Advanced JavaReplies: 1Last Post: 06-06-2007, 03:22 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks