users@glassfish.java.net

OneToMany Web Service END_ELEMENT vs START_ELEMENT

From: kriskross <jump9898_at_hotmail.com>
Date: Sun, 9 Sep 2007 08:20:02 -0700 (PDT)

Hi, hope somone can helpe here.
I'm having two objects(Product and VareLager)(code pastet at the end) with a
bedirectional onetoMany ManyToOne.
I've created a web Service that allows the end user to access the objects.
But..
When I have a object Product with no VareLager, it works.
When I add a VareLager to Product I get an error (pated below).
If I try get the same Object (Product) in a Web Service returning a String,
I get the correct result.
[code]
Product p = pfr.find(2);
String ret = p.getName() + " | " + p.getId();
for(VareLager vl : p.getVareLagers()) {
     ret += " |VL:" + vl.getId() + "|" + vl.getAntallLager();
}
return ret;
[/code]

Can eny one explain to me why, and what I can do to avoid this. I need both
Produkt and VareLager objects in my web service?


ERROR:
javax.xml.ws.WebServiceException: unexpected XML reader state. expected:
END_ELEMENT but found: START_ELEMENT
        at
com.sun.xml.internal.ws.encoding.soap.client.SOAPXMLDecoder.toInternalMessage(SOAPXMLDecoder.java:279)
        at
com.sun.xml.internal.ws.protocol.soap.client.SOAPMessageDispatcher.receive(SOAPMessageDispatcher.java:536)
        at
com.sun.xml.internal.ws.protocol.soap.client.SOAPMessageDispatcher.doSend(SOAPMessageDispatcher.java:260)
        at
com.sun.xml.internal.ws.protocol.soap.client.SOAPMessageDispatcher.send(SOAPMessageDispatcher.java:139)
        at
com.sun.xml.internal.ws.encoding.soap.internal.DelegateBase.send(DelegateBase.java:86)
        at
com.sun.xml.internal.ws.client.EndpointIFInvocationHandler.implementSEIMethod(EndpointIFInvocationHandler.java:174)
        at
com.sun.xml.internal.ws.client.EndpointIFInvocationHandler.invoke(EndpointIFInvocationHandler.java:108)
        at $Proxy16.findProdukt(Unknown Source)
        at testws.Main.main(Main.java:43)
Caused by: unexpected XML reader state. expected: END_ELEMENT but found:
START_ELEMENT
        at
com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.verifyReaderState(XMLStreamReaderUtil.java:191)
        at
com.sun.xml.internal.ws.encoding.soap.SOAPDecoder.decodeBody(SOAPDecoder.java:309)
        at
com.sun.xml.internal.ws.encoding.soap.client.SOAPXMLDecoder.decodeBody(SOAPXMLDecoder.java:199)
        at
com.sun.xml.internal.ws.encoding.soap.client.SOAPXMLDecoder.decodeEnvelope(SOAPXMLDecoder.java:144)
        at
com.sun.xml.internal.ws.encoding.soap.client.SOAPXMLDecoder.toInternalMessage(SOAPXMLDecoder.java:272)
        ... 8 more


@Entity
public class Product implements Serializable {
    private List<VareLager> vareLagers;

    private static final long serialVersionUID = 1L;
    private Integer id;
    private String name;

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

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Integer getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @OneToMany(cascade = CascadeType.ALL, mappedBy="product", fetch =
FetchType.EAGER)
    public List<VareLager> getVareLagers() {
        return vareLagers;
    }

    public void setVareLagers(List<VareLager> vareLagers) {
        this.vareLagers = vareLagers;
    }
}

@Entity
public class VareLager implements Serializable {
    private Product product;
    private static final long serialVersionUID = 1L;
    private Integer id;

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

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Integer getId() {
        return id;
    }

    public int getAntallLager() {
        return antallLager;
    }

    public void setAntallLager(int antallLager) {
        this.antallLager = antallLager;
    }

     @ManyToOne
    @JoinColumn(name = "produkt_id")
    public Product getProduct() {
        return product;
    }

    public void setProduct(Product product) {
        this.product = product;
    }
}

-- 
View this message in context: http://www.nabble.com/OneToMany-Web-Service-END_ELEMENT-vs-START_ELEMENT-tf4409709.html#a12579819
Sent from the java.net - glassfish users mailing list archive at Nabble.com.