由于延迟初始化异常,我的webService未针对SOAP返回正确的响应

时间:2019-01-31 12:07:24

标签: spring web-services soap spring-data glassfish

我有一个正在运行的Web服务,并且可以在正确的URL上阅读我的wsdl。 我也有可以使用的服务,模型和使用者,因为当我以调试模式发送请求时,我从数据库中看到了结果。 但是,当我的WebMethod返回结果时,我只有一个空响应,并且在glassfish日志中显示一条错误: 无法懒惰地初始化角色集合:p3.model.book.Book.borrowing,无法初始化代理-没有会话

我觉得这是我借钱的懒惰,但事实并非如此。

  

[2019-01-31T12:53:50.804 + 0100] [glassfish 5.0] [SeverE] [] [com.sun.xml.ws.servlet.http] [tid:_ThreadID = 32 _ThreadName = http-listener- 1(1)] [timeMillis:1548935630804] [levelValue:1000] [[     被抓   org.hibernate.LazyInitializationException:无法延迟初始化角色集合:p3.model.book.Book.borrowing,无法初始化代理-没有会话       在org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:602)处       在org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:217)       在org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:581)       在org.hibernate.collection.internal.AbstractPersistentCollection.read(AbstractPersistentCollection.java:148)       在org.hibernate.collection.internal.PersistentBag.iterator(PersistentBag.java:303)       在com.sun.xml.bind.v2.runtime.reflect.Lister $ CollectionLister.iterator(Lister.java:281)       在com.sun.xml.bind.v2.runtime.reflect.Lister $ CollectionLister.iterator(Lister.java:268)       在com.sun.xml.bind.v2.runtime.property.ArrayElementProperty.serializeListBody(ArrayElementProperty.java:133)       在com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:159)       在com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:360)       在com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:696)       在com.sun.xml.bind.v2.runtime.property.ArrayElementNodeProperty.serializeItem(ArrayElementNodeProperty.java:69)       在com.sun.xml.bind.v2.runtime.property.ArrayElementProperty.serializeListBody(ArrayElementProperty.java:172)       在com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:159)       在com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:360)       在com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:696)       在com.sun.xml.bind.v2.runtime.property.ArrayElementNodeProperty.serializeItem(ArrayElementNodeProperty.java:69)       在com.sun.xml.bind.v2.runtime.property.ArrayElementProperty.serializeListBody(ArrayElementProperty.java:172)       在com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:159)       在com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:360)       在com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:696)       在com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:276)       在com.sun.xml.bind.v2.runtime.BridgeImpl.marshal(BridgeImpl.java:104)       在com.sun.xml.bind.api.Bridge.marshal(Bridge.java:145)       在com.sun.xml.ws.db.glassfish.BridgeWrapper.marshal(BridgeWrapper.java:176)       在com.sun.xml.ws.message.jaxb.JAXBMe​​ssage.writePayloadTo(JAXBMe​​ssage.java:415)       在com.sun.xml.ws.message.AbstractMessageImpl.writeTo(AbstractMessageImpl.java:192)       在com.sun.xml.ws.api.message.MessageWrapper.writeTo(MessageWrapper.java:226)       在com.sun.xml.ws.encoding.StreamSOAPCodec.encode(StreamSOAPCodec.java:144)       在com.sun.xml.ws.encoding.SOAPBindingCodec.encode(SOAPBindingCodec.java:242)       在com.sun.xml.ws.transport.http.HttpAdapter.encodePacket(HttpAdapter.java:636)       在com.sun.xml.ws.transport.http.HttpAdapter.access $ 100(HttpAdapter.java:108)       在com.sun.xml.ws.transport.http.HttpAdapter $ 3.onCompletion(HttpAdapter.java:739)       在com.sun.xml.ws.server.WSEndpointImpl $ 1.onCompletion(WSEndpointImpl.java:357)       在com.sun.xml.ws.api.pipe.Fiber.completionCheck(Fiber.java:927)       在com.sun.xml.ws.api.pipe.Fiber.run(Fiber.java:823)       在com.sun.xml.ws.api.pipe.Fiber.start(Fiber.java:420)       在com.sun.xml.ws.server.WSEndpointImpl.processAsync(WSEndpointImpl.java:368)       在com.sun.xml.ws.server.WSEndpointImpl.process(WSEndpointImpl.java:398)       在com.sun.xml.ws.metro.api.config.management.ManagedEndpoint.process(ManagedEndpoint.java:234)       在com.sun.xml.ws.transport.http.HttpAdapter.invokeAsync(HttpAdapter.java:734)       在com.sun.xml.ws.transport.http.servlet.ServletAdapter.invokeAsync(ServletAdapter.java:212)       在com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doGet(WSServletDelegate.java:161)       在com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doPost(WSServletDelegate.java:197)       在com.sun.xml.ws.transport.http.servlet.WSServlet.doPost(WSServlet.java:81)       在javax.servlet.http.HttpServlet.service(HttpServlet.java:706)       在javax.servlet.http.HttpServlet.service(HttpServlet.java:791)       在org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1580)       在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:258)       在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)       在org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:652)       在org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:591)       在com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)       在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)       在org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:371)       在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:238)       在com.sun.enterprise.v3.services.impl.ContainerMapper $ HttpHandlerCallable.call(ContainerMapper.java:463)       在com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:168)       在org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)       在org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)       在org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:242)       在org.glassfish.grizzly.filterchain.ExecutorResolver $ 9.execute(ExecutorResolver.java:119)       在org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)       在org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)       在org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)       在org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)       在org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)       在org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:539)       在org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)       在org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)       at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access $ 100(WorkerThreadIOStrategy.java:56)       在org.glassfish.grizzly.strategies.WorkerThreadIOStrategy $ WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)中       在org.glassfish.grizzly.threadpool.AbstractThreadPool $ Worker.doWork(AbstractThreadPool.java:593)       在org.glassfish.grizzly.threadpool.AbstractThreadPool $ Worker.run(AbstractThreadPool.java:573)       在java.lang.Thread.run(Thread.java:748)   ]]

我的wsdl暴露了:

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<!--
 Published by JAX-WS RI (http://jax-ws.java.net). RI's version is Metro/2.4.0 (wsit240-7e98ff4; 2017-08-03T21:19:54+0200) JAXWS-RI/2.3.0 JAXWS-API/2.3.0 JAXB-RI/2.3.0 JAXB-API/2.3.0 svn-revision#unknown. 
-->
<!--
 Generated by JAX-WS RI (http://javaee.github.io/metro-jax-ws). RI's version is Metro/2.4.0 (wsit240-7e98ff4; 2017-08-03T21:19:54+0200) JAXWS-RI/2.3.0 JAXWS-API/2.3.0 JAXB-RI/2.3.0 JAXB-API/2.3.0 svn-revision#unknown. 
-->
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://webService2.p3/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://webService2.p3/" name="workWeb">
<types>
<xsd:schema>
<xsd:import namespace="http://webService2.p3/" schemaLocation="http://localhost:8080/library-webservice/workWs?xsd=1"/>
</xsd:schema>
</types>
<message name="init">
<part name="parameters" element="tns:init"/>
</message>
<message name="initResponse">
<part name="parameters" element="tns:initResponse"/>
</message>
<message name="searchEngineWorkByTitleAndAuthor">
<part name="parameters" element="tns:searchEngineWorkByTitleAndAuthor"/>
</message>
<message name="searchEngineWorkByTitleAndAuthorResponse">
<part name="parameters" element="tns:searchEngineWorkByTitleAndAuthorResponse"/>
</message>
<message name="searchEngineWorkByTitle">
<part name="parameters" element="tns:searchEngineWorkByTitle"/>
</message>
<message name="searchEngineWorkByTitleResponse">
<part name="parameters" element="tns:searchEngineWorkByTitleResponse"/>
</message>
<message name="searchEngineWorkByAuthor">
<part name="parameters" element="tns:searchEngineWorkByAuthor"/>
</message>
<message name="searchEngineWorkByAuthorResponse">
<part name="parameters" element="tns:searchEngineWorkByAuthorResponse"/>
</message>
<portType name="workWs">
<operation name="init">
<input wsam:Action="http://webService2.p3/workWs/initRequest" message="tns:init"/>
<output wsam:Action="http://webService2.p3/workWs/initResponse" message="tns:initResponse"/>
</operation>
<operation name="searchEngineWorkByTitleAndAuthor">
<input wsam:Action="http://webService2.p3/workWs/searchEngineWorkByTitleAndAuthorRequest" message="tns:searchEngineWorkByTitleAndAuthor"/>
<output wsam:Action="http://webService2.p3/workWs/searchEngineWorkByTitleAndAuthorResponse" message="tns:searchEngineWorkByTitleAndAuthorResponse"/>
</operation>
<operation name="searchEngineWorkByTitle">
<input wsam:Action="http://webService2.p3/workWs/searchEngineWorkByTitleRequest" message="tns:searchEngineWorkByTitle"/>
<output wsam:Action="http://webService2.p3/workWs/searchEngineWorkByTitleResponse" message="tns:searchEngineWorkByTitleResponse"/>
</operation>
<operation name="searchEngineWorkByAuthor">
<input wsam:Action="http://webService2.p3/workWs/searchEngineWorkByAuthorRequest" message="tns:searchEngineWorkByAuthor"/>
<output wsam:Action="http://webService2.p3/workWs/searchEngineWorkByAuthorResponse" message="tns:searchEngineWorkByAuthorResponse"/>
</operation>
</portType>
<binding name="workWsPortBinding" type="tns:workWs">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="init">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="searchEngineWorkByTitleAndAuthor">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="searchEngineWorkByTitle">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="searchEngineWorkByAuthor">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="workWeb">
<port name="workWsPort" binding="tns:workWsPortBinding">
<soap:address location="http://localhost:8080/library-webservice/workWs"/>
</port>
</service>
</definitions>

我的模特:

package p3.model.book;

import p3.model.borrowing.Borrowing;
import p3.model.work.Work;

import java.io.Serializable;
import java.util.List;

import javax.persistence.*;
import javax.xml.bind.annotation.XmlType;

@Entity
@Table(name = "book")
@XmlType(name = "Book")
public class Book implements Serializable {

    @Id
    @GeneratedValue(generator = "gen_book", strategy = GenerationType.IDENTITY)
    @SequenceGenerator(name = "gen_book", sequenceName = "seq_book", allocationSize = 1)
    Integer id;

    private String referenceCode;

    private boolean isAvailable;

    @ManyToOne
    private Work works;

    @OneToMany
    private List<Borrowing> borrowing;

    public Book(String referenceCode, boolean isAvailable) {
        this.referenceCode = referenceCode;
        this.isAvailable = isAvailable;
    }

    public Book(String referenceCode, boolean isAvailable, Work works) {
        this.referenceCode = referenceCode;
        this.isAvailable = isAvailable;
        this.works = works;
    }

    public Book() {
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getReferenceCode() {
        return referenceCode;
    }

    public void setReferenceCode(String referenceCode) {
        this.referenceCode = referenceCode;
    }

    public boolean isAvailable() {
        return isAvailable;
    }

    public void setAvailable(boolean isAvailable) {
        this.isAvailable = isAvailable;
    }

    public Work getWorks() {
        return works;
    }

    public void setWorks(Work works) {
        this.works = works;
    }

    public List<Borrowing> getBorrowing() {
        return borrowing;
    }

    public void setBorrowing(List<Borrowing> borrowing) {
        this.borrowing = borrowing;
    }
}

在调试模式下,我遇到了麻烦,我不知道如何解决:

debug before response returned

有人有主意吗?

谢谢您的阅读和帮助。

亚历山大。

1 个答案:

答案 0 :(得分:0)

我解决了这样修改模型的麻烦:(删除注释)

package p3.model.book;

import p3.model.work.Work;

import java.io.Serializable;
import java.util.List;

import javax.persistence.*;
import javax.xml.bind.annotation.XmlType;

@Entity
@Table(name = "book")
//@XmlType(name = "Book")
public class Book implements Serializable {

    @Id
    @GeneratedValue(generator = "gen_book", strategy = GenerationType.IDENTITY)
    @SequenceGenerator(name = "gen_book", sequenceName = "seq_book", allocationSize = 1)
    Integer id;

    private String referenceCode;

    private boolean isAvailable;



    public Book(String referenceCode, boolean isAvailable) {
        this.referenceCode = referenceCode;
        this.isAvailable = isAvailable;
    }

    public Book() {
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getReferenceCode() {
        return referenceCode;
    }

    public void setReferenceCode(String referenceCode) {
        this.referenceCode = referenceCode;
    }

    public boolean isAvailable() {
        return isAvailable;
    }

    public void setAvailable(boolean isAvailable) {
        this.isAvailable = isAvailable;
    }


}