0 Replies Latest reply on Jan 30, 2006 6:24 AM by Marcelo Giorgi

    Hibernate trhough Session beans

    Marcelo Giorgi Newbie

      Hi,

      I am a newbie in JBoss and Hibernate and I have the following situation:

      I use Hiberante 2.1.7 integrated with JBoss 3.2.3 and we have the problem that, by default, Hibernate loads the objects with all the assosiated objects and that means that for every simple query that is made Hibernate constructs the hole Object with information that, for most cases, it is not necesary. So we tried to use the lazy="true" (in the mapping files) in that way Hibernate retrieves the object "on-demand", but we had problems here is what happend:

      The problem is that our business layer uses Session Beans for scalability. This way when a service is required it is provided by the Session Bean which eventually use Hibernate to retrieve the information from a database. When lazy where equal to false, there were no problem because a Session Bean method encapsulate a transaction and Hibernate query ran inside that transaction. The problem appears when lazy="true" because, at the end of the execution of the business method of the Session bean the application server, JBoss 3.2.3, fails and throws the following log:

      2006-01-26 14:56:15,750 INFO [org.jboss.resource.connectionmanager.CachedConnectionManager] Closing a connection for you. Please close them yourself: org.jboss.resource.adapter.jdbc.WrappedConnection@1116790
      java.lang.Exception: STACKTRACE
      at org.jboss.resource.connectionmanager.CachedConnectionManager.registerConnection(CachedConnectionManager.java:282)
      at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:506)
      at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:814)
      at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:102)
      at net.sf.hibernate.connection.DatasourceConnectionProvider.getConnection(DatasourceConnectionProvider.java:59)
      at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:289)
      at net.sf.hibernate.impl.SessionImpl.connect(SessionImpl.java:3361)
      at net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:3321)
      at net.sf.hibernate.impl.BatcherImpl.prepareQueryStatement(BatcherImpl.java:66)
      at net.sf.hibernate.loader.Loader.prepareQueryStatement(Loader.java:779)
      at net.sf.hibernate.loader.Loader.doQuery(Loader.java:265)
      at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
      at net.sf.hibernate.loader.Loader.doList(Loader.java:1033)
      at net.sf.hibernate.loader.Loader.list(Loader.java:1024)
      at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
      at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1553)
      at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
      at net.sf.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:550)
      at uy.com.isbel.crmop.incidents.core.IncidentServicesImpl.getIncidentStatusByCode(IncidentServicesImpl.java:2155)
      at uy.com.isbel.crmop.incidents.ejb.IncidentServicesBean.getIncidentStatusByCode(IncidentServicesBean.java:517)
      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 org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:683)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:185)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:84)
      at org.jboss.ejb.plugins.AbstractTxInterceptorBMT.invokeNext(AbstractTxInterceptorBMT.java:144)
      at org.jboss.ejb.plugins.TxInterceptorBMT.invoke(TxInterceptorBMT.java:62)
      at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:72)
      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:118)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:191)
      at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
      at org.jboss.ejb.StatelessSessionContainer.internalInvoke(StatelessSessionContainer.java:331)
      at org.jboss.ejb.Container.invoke(Container.java:700)
      at org.jboss.ejb.plugins.local.BaseLocalProxyFactory.invoke(BaseLocalProxyFactory.java:375)
      at org.jboss.ejb.plugins.local.StatelessSessionProxy.invoke(StatelessSessionProxy.java:83)
      at $Proxy66.getIncidentStatusByCode(Unknown Source)
      at uy.com.isbel.crmop.incidents.services.IncidentServicesBusinessDelegate.getIncidentStatusByCode(IncidentServicesBusinessDelegate.java:526)
      at uy.com.isbel.crmop.presentation.controller.PruebaFilter.something(PruebaFilter.java:52)
      at uy.com.isbel.crmop.presentation.controller.PruebaFilter.pageRequested(PruebaFilter.java:78)
      at com.salmonllc.html.HtmlPage.notifyListeners(HtmlPage.java:1169)
      at com.salmonllc.jsp.JspController.notifyListeners(JspController.java:1219)
      at com.salmonllc.jsp.JspController.doGet(JspController.java:701)
      at com.salmonllc.jsp.tags.PageTag.doStartTag(PageTag.java:224)
      at org.apache.jsp.pruebaFilter_jsp._jspx_meth_salmon_page_0(pruebaFilter_jsp.java:147)
      at org.apache.jsp.pruebaFilter_jsp._jspService(pruebaFilter_jsp.java:109)
      at com.salmonllc.jsp.JspServlet.service(JspServlet.java:332)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
      at uy.com.isbel.web.filter.HibernateThreadFilter.doFilter(HibernateThreadFilter.java:41)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:213)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      at org.jboss.web.tomcat.security.JBossSecurityMgrRealm.invoke(JBossSecurityMgrRealm.java:220)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
      at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
      at org.jboss.web.tomcat.tc4.statistics.ContainerStatsValve.invoke(ContainerStatsValve.java:76)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2417)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:65)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:577)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:197)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:781)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:549)
      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)
      2006-01-26 14:56:15,765 INFO [STDOUT] parece joda3772
      2006-01-26 14:56:15,765 INFO [STDOUT] Hibernate: select user0_.IdUsuario as IdUsuario1_, user0_.Nombre as Nombre1_, user0_.Email as Email1_, user0_.DESCRIPCION as DESCRIPC4_1_, user0_.BORRADO as BORRADO1_, user0_.IDCANAL as IDCANAL1_, channel1_.ID as ID0_, channel1_.CODIGO as CODIGO0_, channel1_.DESCRIPCION as DESCRIPC3_0_, channel1_.HABILITADO as HABILITADO0_ from Usuarios user0_, CANALES channel1_ where user0_.IdUsuario=? and user0_.IDCANAL=channel1_.ID(+)
      2006-01-26 14:56:15,765 WARN [net.sf.hibernate.util.JDBCExceptionReporter] SQL Error: 0, SQLState: null
      2006-01-26 14:56:15,765 ERROR [net.sf.hibernate.util.JDBCExceptionReporter] Connection handle has been closed and is unusable
      2006-01-26 14:56:15,781 WARN [net.sf.hibernate.util.JDBCExceptionReporter] SQL Error: 0, SQLState: null
      2006-01-26 14:56:15,781 ERROR [net.sf.hibernate.util.JDBCExceptionReporter] Connection handle has been closed and is unusable
      2006-01-26 14:56:15,781 ERROR [net.sf.hibernate.proxy.LazyInitializer] Exception initializing proxy
      net.sf.hibernate.exception.GenericJDBCException: could not load: [uy.com.isbel.crmop.security.vo.User#426]
      at net.sf.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:90)
      at net.sf.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:79)
      at net.sf.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:30)
      at net.sf.hibernate.persister.AbstractEntityPersister.convert(AbstractEntityPersister.java:1332)
      at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:418)
      at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:2130)
      at net.sf.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:1944)
      at net.sf.hibernate.proxy.LazyInitializer.initialize(LazyInitializer.java:53)
      at net.sf.hibernate.proxy.LazyInitializer.initializeWrapExceptions(LazyInitializer.java:60)
      at net.sf.hibernate.proxy.LazyInitializer.getImplementation(LazyInitializer.java:164)
      at net.sf.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:108)
      at uy.com.isbel.crmop.security.vo.User$$EnhancerByCGLIB$$8bb5a917.getName()
      at uy.com.isbel.crmop.presentation.controller.PruebaFilter.something(PruebaFilter.java:73)
      at uy.com.isbel.crmop.presentation.controller.PruebaFilter.pageRequested(PruebaFilter.java:78)
      at com.salmonllc.html.HtmlPage.notifyListeners(HtmlPage.java:1169)
      at com.salmonllc.jsp.JspController.notifyListeners(JspController.java:1219)
      at com.salmonllc.jsp.JspController.doGet(JspController.java:701)
      at com.salmonllc.jsp.tags.PageTag.doStartTag(PageTag.java:224)
      at org.apache.jsp.pruebaFilter_jsp._jspx_meth_salmon_page_0(pruebaFilter_jsp.java:147)
      at org.apache.jsp.pruebaFilter_jsp._jspService(pruebaFilter_jsp.java:109)
      at com.salmonllc.jsp.JspServlet.service(JspServlet.java:332)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
      at uy.com.isbel.web.filter.HibernateThreadFilter.doFilter(HibernateThreadFilter.java:41)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:213)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      at org.jboss.web.tomcat.security.JBossSecurityMgrRealm.invoke(JBossSecurityMgrRealm.java:220)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
      at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
      at org.jboss.web.tomcat.tc4.statistics.ContainerStatsValve.invoke(ContainerStatsValve.java:76)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2417)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:65)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:577)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:197)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:781)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:549)
      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)
      Caused by: java.sql.SQLException: Connection handle has been closed and is unusable
      at org.jboss.resource.adapter.jdbc.WrappedConnection.checkStatus(WrappedConnection.java:774)
      at org.jboss.resource.adapter.jdbc.WrappedConnection.checkTransaction(WrappedConnection.java:759)
      at org.jboss.resource.adapter.jdbc.WrappedConnection.prepareStatement(WrappedConnection.java:208)
      at net.sf.hibernate.impl.BatcherImpl.getPreparedStatement(BatcherImpl.java:260)
      at net.sf.hibernate.impl.BatcherImpl.getPreparedStatement(BatcherImpl.java:235)
      at net.sf.hibernate.impl.BatcherImpl.prepareQueryStatement(BatcherImpl.java:66)
      at net.sf.hibernate.loader.Loader.prepareQueryStatement(Loader.java:779)
      at net.sf.hibernate.loader.Loader.doQuery(Loader.java:265)
      at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
      at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:911)
      at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:931)
      at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:59)
      at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:51)
      at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:415)
      ... 62 more

      Another important thing to mention is when I use the exact same code that is defined inside the Session Bean method (which uses Hibernate) works just fine if i use it outside the Sesssion Bean method, for example if I use it in the presentation layer directly I just works with lazy="true"

      Any suggestion would help me,

      Thanks a lot.
      Marcelo.