Announcement Announcement Module
Collapse
No announcement yet.
Spring & DWR LazyInitializationException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring & DWR LazyInitializationException

    Hi All,

    I started working with DWR in Spring 1 day back. I have one serious issue.

    I have company drop down and i want to get dealer drop down from DWR.
    I have made correct set up in dwr.xml. when i expose my dwr script and run my method i am getting exception like this:

    2008-10-16 19:20:48,143 ERROR [org.hibernate.LazyInitializationException] - MESSAGE : failed to lazily initialize a collection of role: com.ifw.admin.domain.Ifw
    Companies.crmSourceses, no session or session was closed -
    org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.ifw.admin.domain.IfwCompanies.crmSourceses, no session or sessi
    on was closed
    at org.hibernate.collection.AbstractPersistentCollect ion.throwLazyInitializationException(AbstractPersi stentCollection.java:358)
    at org.hibernate.collection.AbstractPersistentCollect ion.throwLazyInitializationExceptionIfNotConnected (AbstractPersistentCollection.java:350)
    at org.hibernate.collection.AbstractPersistentCollect ion.initialize(AbstractPersistentCollection.java:3 43)
    at org.hibernate.collection.AbstractPersistentCollect ion.read(AbstractPersistentCollection.java:86)
    at org.hibernate.collection.PersistentSet.iterator(Pe rsistentSet.java:163)
    at org.directwebremoting.convert.CollectionConverter. convertOutbound(CollectionConverter.java:182)
    at org.directwebremoting.dwrp.DefaultConverterManager .convertOutbound(DefaultConverterManager.java:192)
    at org.directwebremoting.convert.BasicObjectConverter .convertOutbound(BasicObjectConverter.java:189)
    at org.directwebremoting.dwrp.DefaultConverterManager .convertOutbound(DefaultConverterManager.java:192)
    at org.directwebremoting.convert.CollectionConverter. convertOutbound(CollectionConverter.java:206)
    at org.directwebremoting.dwrp.DefaultConverterManager .convertOutbound(DefaultConverterManager.java:192)
    at org.directwebremoting.extend.ScriptBufferUtil.crea teOutput(ScriptBufferUtil.java:56)
    at org.directwebremoting.dwrp.BaseCallMarshaller$Call ScriptConduit.addScript(BaseCallMarshaller.java:51 2)
    at org.directwebremoting.extend.EnginePrivate.remoteH andleCallback(EnginePrivate.java:56)
    at org.directwebremoting.dwrp.BaseCallMarshaller.mars hallOutbound(BaseCallMarshaller.java:330)
    at org.directwebremoting.servlet.PlainCallHandler.han dle(PlainCallHandler.java:53)
    at org.directwebremoting.servlet.UrlProcessor.handle( UrlProcessor.java:101)
    at org.directwebremoting.servlet.DwrServlet.doPost(Dw rServlet.java:146)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:710)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:230)
    at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:104)
    at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:261)
    at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:844)
    at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:581)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JIoEndpoint.java:447)
    at java.lang.Thread.run(Thread.java:595)
    2008-10-16 19:20:48,143 WARN [org.directwebremoting.convert.CollectionConverter] - MESSAGE : Conversion error for java.util.ArrayList. -
    org.directwebremoting.extend.MarshallException: Error marshalling com.ifw.admin.domain.IfwCompanies: failed to lazily initialize a collection of role: com.ifw.a
    dmin.domain.IfwCompanies.crmSourceses, no session or session was closed. See the logs for more details.
    at org.directwebremoting.convert.BasicObjectConverter .convertOutbound(BasicObjectConverter.java:200)
    at org.directwebremoting.dwrp.DefaultConverterManager .convertOutbound(DefaultConverterManager.java:192)
    at org.directwebremoting.convert.CollectionConverter. convertOutbound(CollectionConverter.java:206)
    at org.directwebremoting.dwrp.DefaultConverterManager .convertOutbound(DefaultConverterManager.java:192)
    at org.directwebremoting.extend.ScriptBufferUtil.crea teOutput(ScriptBufferUtil.java:56)
    at org.directwebremoting.dwrp.BaseCallMarshaller$Call ScriptConduit.addScript(BaseCallMarshaller.java:51 2)
    at org.directwebremoting.extend.EnginePrivate.remoteH andleCallback(EnginePrivate.java:56)
    at org.directwebremoting.dwrp.BaseCallMarshaller.mars hallOutbound(BaseCallMarshaller.java:330)
    at org.directwebremoting.servlet.PlainCallHandler.han dle(PlainCallHandler.java:53)
    at org.directwebremoting.servlet.UrlProcessor.handle( UrlProcessor.java:101)
    at org.directwebremoting.servlet.DwrServlet.doPost(Dw rServlet.java:146)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:710)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:230)
    at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:104)
    at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:261)
    at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:844)
    at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:581)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JIoEndpoint.java:447)
    at java.lang.Thread.run(Thread.java:595)
    Caused by: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.ifw.admin.domain.IfwCompanies.crmSourceses, no sessi
    on or session was closed



    ***********************

    Please give me the solution for this what i can do... :-(

  • #2
    This is more like DAO issue than MVC.

    See error "org.hibernate.LazyInitializationException"

    The problem is that your Hibernate session is been closed before all the needed data is been read from your database. The collections are read as "lazy" by Hibernate meaning that Hibernate reads the properties but not the content of collection (but is aware that there is one).

    I don't know the most elegant way to fix this problem. It depends when this error occurs in your case. You could try to "touch" the collection in the DAO layer. Hibernate 3 atleast used to have a static "initialize" method in Hibernate class with you were able to initialize properties and collections.

    The other solution is to set lazy loading as false. NOTE! this can have dramatic performance issues later in your application since it loads everything every in to memory.

    I hope this helps...

    Comment

    Working...
    X