Announcement Announcement Module
Collapse
No announcement yet.
Session Object and LazyInitializationException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Session Object and LazyInitializationException

    I confused on why my database objects that I store in a session are becoming invalid when I try to access it in different flows. For a user logs in for one flow and that User object is stored in my HttpSession. In a different flow I access that User object and I get a

    Code:
    org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
    	org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:56)
    	org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:98)
    	org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:158)
    	edu.ucr.c3.rsvp.domain.rsvp.Reception$$EnhancerByCGLIB$$d47934a7.getLocation(<generated>)
    	edu.ucr.c3.rsvp.controller.students.StudentStatus.createRSVPInfo(StudentStatus.java:134)
    	edu.ucr.c3.rsvp.controller.students.StudentStatus.viewStatus(StudentStatus.java:99)
    	edu.ucr.c3.rsvp.controller.students.StudentStatus.executeRSVPApp(StudentStatus.java:31)
    	edu.ucr.c3.rsvp.controller.RSVPAction.doExecute(RSVPAction.java:54)
    	org.springframework.webflow.action.AbstractAction.execute(AbstractAction.java:203)
    	org.springframework.webflow.engine.AnnotatedAction.execute(AnnotatedAction.java:142)
    	org.springframework.webflow.engine.ActionExecutor.execute(ActionExecutor.java:61)
    	org.springframework.webflow.engine.ActionList.execute(ActionList.java:160)
    	org.springframework.webflow.engine.ViewState.doEnter(ViewState.java:99)
    	org.springframework.webflow.engine.State.enter(State.java:200)
    	org.springframework.webflow.engine.Transition.execute(Transition.java:229)
    	org.springframework.webflow.engine.TransitionableState.onEvent(TransitionableState.java:112)
    	org.springframework.webflow.engine.Flow.onEvent(Flow.java:572)
    	org.springframework.webflow.engine.impl.RequestControlContextImpl.signalEvent(RequestControlContextImpl.java:208)
    	org.springframework.webflow.engine.ActionState.doEnter(ActionState.java:185)
    	org.springframework.webflow.engine.State.enter(State.java:200)
    	org.springframework.webflow.engine.Flow.start(Flow.java:557)
    	org.springframework.webflow.engine.impl.RequestControlContextImpl.start(RequestControlContextImpl.java:196)
    	org.springframework.webflow.engine.impl.FlowExecutionImpl.start(FlowExecutionImpl.java:189)
    	org.springframework.webflow.executor.FlowExecutorImpl.launch(FlowExecutorImpl.java:206)
    	org.springframework.webflow.executor.support.FlowRequestHandler.handleFlowRequest(FlowRequestHandler.java:131)
    	org.springframework.webflow.executor.mvc.FlowController.handleRequestInternal(FlowController.java:172)
    	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:857)
    	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:792)
    	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:461)
    	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:416)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    	org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
    	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75)
    But if I query the database at the begining of a flow and store the object in the session, any state within that same flow can access the object just fine. The reason I stored it in the HttpSession was so that I could access it across flows, but for some reason the object is getting closed out between flows instead. does anyone know a work around this? is it a scope issue and I can't use sessions or what?
    thanks
    -Ray

  • #2
    Hello,

    do you store your hibernate session into the flow ?

    There are 2 ways to avoid the lazyloadingexceptions, first one will be to use the session in which the object was created (session per conversation), or to reattach the object into a new session before using it (session per request).

    Of course, you can also initialize all the collection, then you will also avoid the lazyloadingexceptions.

    regards
    agim

    Comment


    • #3
      No i dont store the hibernate session anywhere, this is the first time ive run across a problem like this before so I was kind of lost on what to do. I would like to avoid initializing all the objects, even though in this project that would be fine....i kinda of want to keep things consistent with other projects where that would be an issue. so for your first 2 options, do you have any small examples on how that would be done? like I said ive never run into this problem and based on my framework layout im not sure how I would do those things.
      For my data access I used DAO beans that are initialized in my applicationContext and those beans are injected into a service transaction proxy. My actual DAO classes extend HibernateDAOSupport.
      so what your saying would be to pass my existing objects back through the proxy into the DAO object, then somehow reconnect it to the current session??
      please advice
      thanks
      -Ray

      Comment


      • #4
        the object that you try to view in your jsp is a simple pojo???

        if your pojo has more classes in the association and you need to see them in the jsp too
        you should initialize they too

        getHibernateTemplate().initialize(pojo);//<-- try it if only is a simple pojo
        getHibernateTemplate().initialize(pojo.getOtherPoj o);

        now if you post some codefor DAO methods in SWF , it would be useful

        regards

        Comment

        Working...
        X