1 Reply Latest reply on Nov 13, 2007 5:55 PM by shane.bryzak

    webservice and JPA LazyInitializationException

    mwkohout

      Following the instructions in the webservices chapter of the documentation, I've got a small webservice that I've integrated into Seam...It reaches into the context, then pulls out one of my jpa home/dao objects.

      The only problem is that some of the relationships are lazy and I speculate responsible for a LazyInitializationException I'm seeing when the java objects are being marshalled into xml.

      here's part of the stack trace:

      13:33:16,685 ERROR [[StudyService]] Servlet.service() for servlet StudyService threw exception
      org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: edu.umn.ictr.core.model.Study.IRBStudyIDs, 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.initialize(AbstractPersistentCollection.java:343)
       at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
       at org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:163)
       at edu.umn.ictr.core.model.Study.getIRBStudies(Study.java:133)
       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:585)
       at com.sun.xml.bind.v2.runtime.reflect.Accessor$GetterSetterReflection.get(Accessor.java:266)
       at com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:92)
       at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:286)
       at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:619)
       at com.sun.xml.bind.v2.runtime.property.ArrayElementNodeProperty.serializeItem(ArrayElementNodeProperty.java:29)
       at com.sun.xml.bind.v2.runtime.property.ArrayElementProperty.serializeListBody(ArrayElementProperty.java:132)
       at com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:101)
       at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:286)
       at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:619)
       at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBeanInfoImpl.java:93)
       at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBeanInfoImpl.java:127)
       at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeBody(ElementBeanInfoImpl.java:244)
       at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBeanInfoImpl.java:251)
       at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBeanInfoImpl.java:33)
       at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:461)
       at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:292)
       at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:221)
       at org.jboss.ws.core.jaxws.JAXBSerializer.serialize(JAXBSerializer.java:83)
       at org.jboss.ws.core.jaxrpc.binding.SerializerSupport.serialize(SerializerSupport.java:61)
       at org.jboss.ws.core.soap.ObjectContent.marshallObjectContents(ObjectContent.java:159)
       at org.jboss.ws.core.soap.ObjectContent.transitionTo(ObjectContent.java:72)
       at org.jboss.ws.core.soap.SOAPContentElement.transitionTo(SOAPContentElement.java:140)
       at org.jboss.ws.core.soap.SOAPContentElement.writeElement(SOAPContentElement.java:536)
       at org.jboss.ws.core.soap.SOAPElementImpl.writeElementContent(SOAPElementImpl.java:834)
       at org.jboss.ws.core.soap.SOAPElementImpl.writeElement(SOAPElementImpl.java:819)
       at org.jboss.ws.core.soap.SOAPElementImpl.writeElementContent(SOAPElementImpl.java:834)
       at org.jboss.ws.core.soap.SOAPElementImpl.writeElement(SOAPElementImpl.java:819)
       at org.jboss.ws.core.soap.SOAPElementWriter.writeElementInternal(SOAPElementWriter.java:149)
       at org.jboss.ws.core.soap.SOAPElementWriter.writeElement(SOAPElementWriter.java:130)
       at org.jboss.ws.core.soap.SOAPMessageImpl.writeTo(SOAPMessageImpl.java:291)
       at org.jboss.ws.core.server.ServiceEndpointManager.sendResponse(ServiceEndpointManager.java:517)
       at org.jboss.ws.core.server.ServiceEndpointManager.processRequest(ServiceEndpointManager.java:481)
       at org.jboss.ws.core.server.AbstractServiceEndpointServlet.doPost(AbstractServiceEndpointServlet.java:114)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
       at org.jboss.ws.core.server.AbstractServiceEndpointServlet.service(AbstractServiceEndpointServlet.java:75)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
       at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
       at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
       at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
       at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
       at java.lang.Thread.run(Thread.java:595)
      


      Is there any way I can force the Seam WebService Endpoint(or some other part of the mechanism) to force all those relationships to be populated thus avoiding my problem, or is making a set of web service dtos my only choice?

      thanks

        • 1. Re: webservice and JPA LazyInitializationException
          shane.bryzak

          In situations like this I usually force the collections to load by "touching" them, however depending how deep your object graph is, it might be a better option to create DTO's otherwise you may end up sending half your database. I had the same issue with remoting (which is the reason I added the "exclude" attribute to @WebRemote) however there is no equivalent solution for web services.