-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Lazy loading problems after transaction rollback
PostPosted: Fri Jul 07, 2006 11:16 pm 
Newbie

Joined: Tue May 24, 2005 7:08 pm
Posts: 17
Location: Melbourne
Could someone confirm whether this is expected behaviour or a bug. I have a web app using the Spring OpenSessionInViewFilter. My controller code looks as follows (setup for test purposes only):

Code:
...
Set developers;

try {
         projectManager.saveProject(project);

      } catch(DataIntegrityViolationException  e)
      {
         errors.rejectValue("title", "errors.uniqueConstraintViolation");
         developers = project.getDevelopers();
         return showForm(request, response, errors);
      }

      developers = project.getDevelopers();
...


I am finding that if projectManager.saveProject(project); executes without an exception bing thrown, project.getDevelopers() works fine and loads the lazy collection.

However, if a DataIntegrityViolationException is thrown by the save and caught, I get a lazy loading problem when I try to load the developers set.

I've dug into this and am sure that the session is not being closed by the transaction rollback. It appears that something is clearing persitent collections in the handling of the exception so when the code below runs it doesn't see the developers set in the session's persistenceContext ... I just can't see what.

from class: AbstractPersistentCollection
Code:
private final boolean isConnectedToSession() {
      return session!=null &&
            session.isOpen() &&
            session.getPersistenceContext().containsCollection(this);
   }


Any ideas ?

Hibernate version:3.13

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:
Code:
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: au.com.groupware.itrack.model.Project.developers, no session or session was closed
   at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358)
   at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350)
   at org.hibernate.collection.AbstractPersistentCollection.readElementExistence(AbstractPersistentCollection.java:132)
   at org.hibernate.collection.PersistentSet.contains(PersistentSet.java:131)
   at au.com.groupware.itrack.web.controller.ProjectController.referenceData(ProjectController.java:70)
   at org.springframework.web.servlet.mvc.AbstractFormController.showForm(AbstractFormController.java:555)
   at org.springframework.web.servlet.mvc.SimpleFormController.showForm(SimpleFormController.java:193)
   at org.springframework.web.servlet.mvc.SimpleFormController.showForm(SimpleFormController.java:172)
   at au.com.groupware.itrack.web.controller.ProjectController.save(ProjectController.java:340)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:324)
   at au.com.groupware.web.controller.AbstractBaseFormController.onSubmit(AbstractBaseFormController.java:273)
   at org.springframework.web.servlet.mvc.SimpleFormController.processFormSubmission(SimpleFormController.java:258)
   at org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:249)
   at au.com.groupware.web.controller.AbstractBaseFormController.handleRequestInternal(AbstractBaseFormController.java:511)
   at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
   at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:44)
   at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:723)
   at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:663)
   at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:394)
   at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:358)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:284)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
   at com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:118)
   at com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:52)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:233)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
   at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:174)
   at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:233)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
   at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:264)
   at org.acegisecurity.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:107)
   at org.acegisecurity.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:72)
   at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
   at org.acegisecurity.ui.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:110)
   at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
   at org.acegisecurity.providers.anonymous.AnonymousProcessingFilter.doFilter(AnonymousProcessingFilter.java:125)
   at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
   at org.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:216)
   at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
   at org.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:195)
   at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
   at org.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:148)
   at org.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:90)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:233)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
   at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:245)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:199)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:509)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:195)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:164)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:156)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:972)
   at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:211)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:805)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:696)
   at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:605)
   at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:677)
   at java.lang.Thread.run(Thread.java:534)


Name and version of the database you are using: MySQL 4


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 10, 2006 8:18 pm 
Newbie

Joined: Mon May 23, 2005 7:31 pm
Posts: 3
I've also noticed this happening previously - does anyone have any solution to this?

thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 11, 2006 4:33 pm 
Regular
Regular

Joined: Tue Jun 22, 2004 8:01 pm
Posts: 106
Location: PowderTown, Utah, USA
I've recently discovered that rolling back transactions causes cache evictions. This can trigger lazy load exceptions if objects in the session have lazy associations (collections in my case). The reason is that the exception causes a roll-back and the cached collections get evicted. If you continue using the same session (say, using the open-session-in-view pattern) and some of the objects in the session have lazy cached collections then you can get lazy initialization exceptions.

This happens often with spring because the transactions are handled for you and automatically result in rollback. One solution is to tell Spring to not roll back the transaction on exception (by using the "+" notation if you're using declarative transaction handling). Another way is to refresh the object before using it, if you suspect that earlier transactions could have dumped your cache.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.