Announcement Announcement Module
Collapse
No announcement yet.
OpenSessionInViewFilter with EJB and CMT Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • OpenSessionInViewFilter with EJB and CMT

    I am trying to use the OpenSessionInViewFilter in tandem with EJB CMT (can't use Spring tx management for political reasons). The filter is opening and closing a Hibernate Session at the beginning and end of a web request as expected. The problem is that the underlying Connection is being closed by the container (in my case, JBoss 3.2.2) upon completion of the (declaratively configured as "RequiresNew") transaction. Thus when a property is lazy-loaded later in the view, the result is the "net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a collection" message.

    So - is there a way to obtain a Session using the filter and be assured that its connection will remain open for the duration of the request? Or, if not, is there a way to configure the Session through Spring to reconnect to obtain a new underlying Connection if it has been closed prior?

  • #2
    I doubt it's possible for Spring to reliably use the connection after the EJB container has finished with it. There might be a way, but the idea makes me a bit nervous--it makes sense that once the transaction is complete, the EJB container will close the connection and make it available for reuse. EJB assumes that nothing will want to access data outside the EJB container.

    I suspect that if you want this feature, your political masters may need to be more flexible :-) Alternatively, is there any way you can do without "open session in view"?

    Comment


    • #3
      Thanks for the response, Rod. That's what I feared would be the case, but wanted to check all avenues before conceding defeat. I can proceed without using the "open session in view" pattern, but life would be much easier (and code much prettier) with it. Will continue to badger my group about ridding ourselves of those nasty little EJBs - though they granted my wishes on Spring & Hibernate, so I can't complain too much.

      Comment


      • #4
        Solution?

        So is there a solution to this "one (CMT + Hibernate) transaction" & lazy loading problem?

        For what I see from all this topics, nothing has been said in a concrete manner:
        1. http://forum.springframework.org/showthread.php?t=9622
        2. http://forum.springframework.org/showthread.php?t=9989
        3. http://forum.springframework.org/showthread.php?t=10910

        If you use one approach you get to another problem. Trying to solve this one you get back to the first one.

        :?

        At 2., is JBoss the only one with this behaviour?
        I mostly seek solution for JBoss 3.2.x.

        Regards, Ales
        Last edited by robyn; May 14th, 2006, 10:42 AM.

        Comment


        • #5
          Solution2?

          I found this on JBoss forum (http://www.jboss.org/index.html?modu...wtopic&t=48491) and it seems to work for me - I don't get the exception at the begining as I used to get.

          In transaction-service.xml set spec-compliant to true.
          But is this really ok? It won't 'drain' my connection pool?

          Btw: I now using Spring's JtaTM + HibenateInterceptor on my DAO used inside my local CMT managed SLSB? Mixin which isn't appropriate?

          Ales

          Comment


          • #6
            Aaarrrgghh ...

            Just created new problems:

            Will continue to look ...

            Ales

            -------- exception stack ------------

            2004-10-20 14:57:30,890 DEBUG [net.sf.hibernate.impl.BatcherImpl] could not log warnings
            java.sql.SQLException: Connection handle is not currently associated with a ManagedConnection
            at org.jboss.resource.adapter.jdbc.WrappedConnection. checkStatus(WrappedConnection.java:784)
            at org.jboss.resource.adapter.jdbc.WrappedConnection. checkTransaction(WrappedConnection.java:765)
            at org.jboss.resource.adapter.jdbc.WrappedConnection. getWarnings(WrappedConnection.java:583)
            at net.sf.hibernate.impl.BatcherImpl.closeConnection( BatcherImpl.java:289)
            at net.sf.hibernate.impl.SessionImpl.disconnect(Sessi onImpl.java:3348)
            at net.sf.hibernate.impl.SessionImpl.close(SessionImp l.java:576)
            at org.springframework.orm.hibernate.SessionFactoryUt ils.doClose(SessionFactoryUtils.java:569)
            at org.springframework.orm.hibernate.SessionFactoryUt ils.closeSessionOrRegisterDeferredClose(SessionFac toryUtils.java:558)
            at org.springframework.orm.hibernate.SessionFactoryUt ils.closeSessionIfNecessary(SessionFactoryUtils.ja va:540)
            at org.springframework.orm.hibernate.support.OpenSess ionInViewInterceptor.afterCompletion(OpenSessionIn ViewInterceptor.java:217)
            at org.springframework.web.servlet.DispatcherServlet. triggerAfterCompletion(DispatcherServlet.java:666)
            at org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:544)
            at org.springframework.web.servlet.FrameworkServlet.s ervice(FrameworkServlet.java:321)
            at javax.servlet.http.HttpServlet.service(HttpServlet .java:810)
            at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:237)
            at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:157)
            at com.generalynx.common.filters.SessionFilter.doFilt er(SessionFilter.java:53)
            at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:186)
            at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:157)
            at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doF ilter(ReplyHeaderFilter.java:75)
            at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:186)
            at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:157)
            at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:214)
            at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:104)
            at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:520)
            at org.apache.catalina.core.StandardContextValve.invo keInternal(StandardContextValve.java:198)
            at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:152)
            at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:104)
            at org.jboss.web.tomcat.security.CustomPrincipalValve .invoke(CustomPrincipalValve.java:66)
            at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:102)
            at org.jboss.web.tomcat.security.SecurityAssociationV alve.invoke(SecurityAssociationValve.java:158)
            at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:102)
            at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:520)
            at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:137)
            at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:104)
            at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:118)
            at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:102)
            at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:520)
            at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:109)
            at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:104)
            at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:520)
            at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:929)
            at org.apache.coyote.tomcat5.CoyoteAdapter.service(Co yoteAdapter.java:160)
            at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:799)
            at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.processConnection(Http11Protocol.jav a:705)
            at org.apache.tomcat.util.net.TcpWorkerThread.runIt(P oolTcpEndpoint.java:577)
            at org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:683)
            at java.lang.Thread.run(Thread.java:534)
            2004-10-20 14:57:30,890 DEBUG [net.sf.hibernate.impl.SessionImpl] transaction completion
            2004-10-20 14:57:30,890 DEBUG [org.springframework.web.servlet.DispatcherServlet] Successfully completed request
            2004-10-20 14:57:30,890 DEBUG [org.springframework.web.context.support.XmlWebAppl icationContext] Publishing event in context [XmlWebApplicationContext for namespace 'egida-servlet']: RequestHandledEvent: url=[/egida/login.htm]; time=[109ms]; client=[127.0.0.1]; method=[POST]; servlet=[egida]; session=[BC374F5D152663F9F804F7E4C76AA131]; user=[null]; status=[OK]
            2004-10-20 14:57:30,890 DEBUG [org.springframework.web.context.support.XmlWebAppl icationContext] Publishing event in context [Root XmlWebApplicationContext]: RequestHandledEvent: url=[/egida/login.htm]; time=[109ms]; client=[127.0.0.1]; method=[POST]; servlet=[egida]; session=[BC374F5D152663F9F804F7E4C76AA131]; user=[null]; status=[OK]

            Comment

            Working...
            X