persistence@glassfish.java.net

Re: _at_OneToMany - _at_ManyToOne WebService and _at_XmlRootElement

From: Sahoo <Sahoo_at_Sun.COM>
Date: Thu, 20 Sep 2007 15:36:33 +0530

Yes, that suggestion works for JAXB as well.

If you didn't like that suggestion, see if the alternatives mentioned
here [1] work for you. You will find some discussions around them in
JAXB & JAX-WS java.net forums as well.

Thanks,
Sahoo

[1] https://jaxb.dev.java.net/guide/Mapping_cyclic_references_to_XML.html

kriskross wrote:
> Ok, tnx, that works for now.
> Not the most sexy sulotion thoug.
> Are there other ways, or will there be other ways?
> (is JAXB working with this)
> Nice to know for next project ;)
>
> Thanks
> Kristian
>
>
>
> Sahoo wrote:
>
>> A similar problem was reported by another GlassFish user and he got
>> things working following our suggestion. Can you take a look at [1] and
>> see if that solves your issue as well.
>>
>> Thanks,
>> Sahoo
>>
>> [1] http://forums.java.net/jive/thread.jspa?messageID=230440
>>
>> kriskross wrote:
>>
>>> Three classes and the stack trace. The sessions is default
>>> sessions-from-entityclasses they are not included.
>>> The webservice has four methods.
>>> 1. Test() - creates a new Parent and return a String with id and name
>>> 2. Test2() - finds the Parent with Id 2, and creates and add a child
>>> 3. getParent1 - finds a parent and returns the id & name + id & name for
>>> childs
>>> 4. getParent2 - finds a parent and return it.
>>> Now when I test this in order. Step 1 - 2 - 3 works perfectly, and the
>>> sql
>>> and data in tables looks nice.
>>> But 4 - gives error.
>>>
>>>
>>> javax.xml.ws.WebServiceException
>>> at
>>> com.sun.xml.ws.message.jaxb.JAXBMessage.writePayloadTo(JAXBMessage.java:300)
>>> at
>>> com.sun.xml.ws.message.AbstractMessageImpl.writeTo(AbstractMessageImpl.java:171)
>>> at
>>> com.sun.xml.ws.message.AbstractMessageImpl.readAsSOAPMessage(AbstractMessageImpl.java:193)
>>> at
>>> com.sun.enterprise.webservice.SOAPMessageContextImpl.getMessage(SOAPMessageContextImpl.java:87)
>>> at
>>> com.sun.enterprise.webservice.monitoring.MessageTraceImpl.setMessageContext(MessageTraceImpl.java:124)
>>> at
>>> com.sun.enterprise.webservice.monitoring.JAXWSEndpointImpl.processResponse(JAXWSEndpointImpl.java:105)
>>> at
>>> com.sun.enterprise.webservice.MonitoringPipe.process(MonitoringPipe.java:155)
>>> at
>>> com.sun.xml.ws.api.pipe.helper.PipeAdapter.processRequest(PipeAdapter.java:115)
>>> at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:595)
>>> at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:554)
>>> at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:539)
>>> at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:436)
>>> at
>>> com.sun.xml.ws.api.pipe.helper.AbstractTubeImpl.process(AbstractTubeImpl.java:106)
>>> at
>>> com.sun.xml.ws.tx.service.TxServerPipe.process(TxServerPipe.java:317)
>>> at
>>> com.sun.enterprise.webservice.CommonServerSecurityPipe.processRequest(CommonServerSecurityPipe.java:218)
>>> at
>>> com.sun.enterprise.webservice.CommonServerSecurityPipe.process(CommonServerSecurityPipe.java:129)
>>> at
>>> com.sun.xml.ws.api.pipe.helper.PipeAdapter.processRequest(PipeAdapter.java:115)
>>> at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:595)
>>> at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:554)
>>> at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:539)
>>> at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:436)
>>> at
>>> com.sun.xml.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:243)
>>> at
>>> com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:444)
>>> at
>>> com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:244)
>>> at
>>> com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:135)
>>> at
>>> com.sun.enterprise.webservice.Ejb3MessageDispatcher.handlePost(Ejb3MessageDispatcher.java:113)
>>> at
>>> com.sun.enterprise.webservice.Ejb3MessageDispatcher.invoke(Ejb3MessageDispatcher.java:87)
>>> at
>>> com.sun.enterprise.webservice.EjbWebServiceServlet.dispatchToEjbEndpoint(EjbWebServiceServlet.java:200)
>>> at
>>> com.sun.enterprise.webservice.EjbWebServiceServlet.service(EjbWebServiceServlet.java:129)
>>> at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
>>> at
>>> com.sun.enterprise.web.AdHocContextValve.invoke(AdHocContextValve.java:114)
>>> at
>>> org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
>>> at
>>> org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
>>> at
>>> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
>>> at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:87)
>>> at
>>> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:206)
>>> at
>>> org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
>>> at
>>> org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
>>> at
>>> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
>>> at
>>> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
>>> at
>>> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:150)
>>> at
>>> org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
>>> at
>>> org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
>>> at
>>> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
>>> at
>>> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
>>> at
>>> org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:270)
>>> at
>>> com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:637)
>>> at
>>> com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:568)
>>> at
>>> com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:813)
>>> at
>>> com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:339)
>>> at
>>> com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:261)
>>> at
>>> com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:212)
>>> at
>>> com.sun.enterprise.web.portunif.PortUnificationPipeline$PUTask.doTask(PortUnificationPipeline.java:361)
>>> at
>>> com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
>>> at
>>> com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
>>> Caused by: javax.xml.bind.MarshalException
>>> - with linked exception:
>>> [com.sun.istack.SAXException2: A cycle is detected in the object graph.
>>> This
>>> will cause infinitely deep XML: entity.Parent_at_10ba2d1 ->
>>> entity.Child_at_ee791d
>>> -> entity.Parent_at_10ba2d1]
>>> at
>>> com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:282)
>>> at
>>> com.sun.xml.bind.v2.runtime.BridgeImpl.marshal(BridgeImpl.java:110)
>>> at com.sun.xml.bind.api.Bridge.marshal(Bridge.java:178)
>>> at
>>> com.sun.xml.ws.message.jaxb.JAXBMessage.writePayloadTo(JAXBMessage.java:294)
>>> ... 54 more
>>> Caused by: com.sun.istack.SAXException2: A cycle is detected in the
>>> object
>>> graph. This will cause infinitely deep XML: entity.Parent_at_10ba2d1 ->
>>> entity.Child_at_ee791d -> entity.Parent_at_10ba2d1
>>> at
>>> com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:244)
>>> at
>>> com.sun.xml.bind.v2.runtime.XMLSerializer.pushObject(XMLSerializer.java:533)
>>> at
>>> com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:627)
>>> at
>>> com.sun.xml.bind.v2.runtime.property.SingleElementNodeProperty.serializeBody(SingleElementNodeProperty.java:150)
>>> at
>>> com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:322)
>>> at
>>> com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:681)
>>> at
>>> com.sun.xml.bind.v2.runtime.property.ArrayElementNodeProperty.serializeItem(ArrayElementNodeProperty.java:65)
>>> at
>>> com.sun.xml.bind.v2.runtime.property.ArrayElementProperty.serializeListBody(ArrayElementProperty.java:168)
>>> at
>>> com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:152)
>>> at
>>> com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:322)
>>> at
>>> com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:681)
>>> at
>>> com.sun.xml.bind.v2.runtime.property.SingleElementNodeProperty.serializeBody(SingleElementNodeProperty.java:150)
>>> at
>>> com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:322)
>>> at
>>> com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:681)
>>> at
>>> com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:277)
>>> ... 57 more
>>> Cannot log SOAP Message null
>>> invocation error on ejb endpoint testWS at /testWSService/testWS :
>>> javax.xml.bind.MarshalException
>>> - with linked exception:
>>> [com.sun.istack.SAXException2: A cycle is detected in the object graph.
>>> This
>>> will cause infinitely deep XML: entity.Parent_at_10ba2d1 ->
>>> entity.Child_at_ee791d
>>> -> entity.Parent_at_10ba2d1]
>>> javax.xml.ws.WebServiceException: javax.xml.bind.MarshalException
>>> - with linked exception:
>>> [com.sun.istack.SAXException2: A cycle is detected in the object graph.
>>> This
>>> will cause infinitely deep XML: entity.Parent_at_10ba2d1 ->
>>> entity.Child_at_ee791d
>>> -> entity.Parent_at_10ba2d1]
>>> at
>>> com.sun.xml.ws.message.jaxb.JAXBMessage.writePayloadTo(JAXBMessage.java:317)
>>> at
>>> com.sun.xml.ws.message.AbstractMessageImpl.writeTo(AbstractMessageImpl.java:142)
>>> at
>>> com.sun.xml.ws.encoding.StreamSOAPCodec.encode(StreamSOAPCodec.java:108)
>>> at
>>> com.sun.xml.ws.encoding.SOAPBindingCodec.encode(SOAPBindingCodec.java:265)
>>> at
>>> com.sun.xml.ws.transport.http.HttpAdapter.encodePacket(HttpAdapter.java:320)
>>> at
>>> com.sun.xml.ws.transport.http.HttpAdapter.access$100(HttpAdapter.java:93)
>>> at
>>> com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:454)
>>> at
>>> com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:244)
>>> at
>>> com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:135)
>>> at
>>> com.sun.enterprise.webservice.Ejb3MessageDispatcher.handlePost(Ejb3MessageDispatcher.java:113)
>>> at
>>> com.sun.enterprise.webservice.Ejb3MessageDispatcher.invoke(Ejb3MessageDispatcher.java:87)
>>> at
>>> com.sun.enterprise.webservice.EjbWebServiceServlet.dispatchToEjbEndpoint(EjbWebServiceServlet.java:200)
>>> at
>>> com.sun.enterprise.webservice.EjbWebServiceServlet.service(EjbWebServiceServlet.java:129)
>>> at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
>>> at
>>> com.sun.enterprise.web.AdHocContextValve.invoke(AdHocContextValve.java:114)
>>> at
>>> org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
>>> at
>>> org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
>>> at
>>> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
>>> at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:87)
>>> at
>>> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:206)
>>> at
>>> org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
>>> at
>>> org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
>>> at
>>> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
>>> at
>>> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
>>> at
>>> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:150)
>>> at
>>> org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
>>> at
>>> org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
>>> at
>>> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
>>> at
>>> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
>>> at
>>> org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:270)
>>> at
>>> com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:637)
>>> at
>>> com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:568)
>>> at
>>> com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:813)
>>> at
>>> com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:339)
>>> at
>>> com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:261)
>>> at
>>> com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:212)
>>> at
>>> com.sun.enterprise.web.portunif.PortUnificationPipeline$PUTask.doTask(PortUnificationPipeline.java:361)
>>> at
>>> com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
>>> at
>>> com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
>>> Caused by: javax.xml.bind.MarshalException
>>> - with linked exception:
>>> [com.sun.istack.SAXException2: A cycle is detected in the object graph.
>>> This
>>> will cause infinitely deep XML: entity.Parent_at_10ba2d1 ->
>>> entity.Child_at_ee791d
>>> -> entity.Parent_at_10ba2d1]
>>> at
>>> com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:282)
>>> at
>>> com.sun.xml.bind.v2.runtime.BridgeImpl.marshal(BridgeImpl.java:100)
>>> at com.sun.xml.bind.api.Bridge.marshal(Bridge.java:141)
>>> at
>>> com.sun.xml.ws.message.jaxb.JAXBMessage.writePayloadTo(JAXBMessage.java:310)
>>> ... 38 more
>>> Caused by: com.sun.istack.SAXException2: A cycle is detected in the
>>> object
>>> graph. This will cause infinitely deep XML: entity.Parent_at_10ba2d1 ->
>>> entity.Child_at_ee791d -> entity.Parent_at_10ba2d1
>>> at
>>> com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:244)
>>> at
>>> com.sun.xml.bind.v2.runtime.XMLSerializer.pushObject(XMLSerializer.java:533)
>>> at
>>> com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:627)
>>> at
>>> com.sun.xml.bind.v2.runtime.property.SingleElementNodeProperty.serializeBody(SingleElementNodeProperty.java:150)
>>> at
>>> com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:322)
>>> at
>>> com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:681)
>>> at
>>> com.sun.xml.bind.v2.runtime.property.ArrayElementNodeProperty.serializeItem(ArrayElementNodeProperty.java:65)
>>> at
>>> com.sun.xml.bind.v2.runtime.property.ArrayElementProperty.serializeListBody(ArrayElementProperty.java:168)
>>> at
>>> com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:152)
>>> at
>>> com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:322)
>>> at
>>> com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:681)
>>> at
>>> com.sun.xml.bind.v2.runtime.property.SingleElementNodeProperty.serializeBody(SingleElementNodeProperty.java:150)
>>> at
>>> com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:322)
>>> at
>>> com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:681)
>>> at
>>> com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:277)
>>> ... 41 more
>>>
>>>
>>>
>>>
>>> @WebService()
>>> @Stateless()
>>> public class testWS {
>>>
>>> @EJB
>>> session.ParentFacadeRemote pfr;
>>>
>>> @EJB
>>> session.ChildFacadeRemote cfr;
>>>
>>> /**
>>> * Web service operation
>>> */
>>> @WebMethod(operationName = "test")
>>> public String test() {
>>> Parent p = new Parent();
>>> p.setName("test1");
>>> pfr.create(p);
>>> String result = "";
>>> @SuppressWarnings("unchecked")
>>> List<Parent> pl = pfr.findAll();
>>> for(Parent pa : pl) {
>>> result += "|" + pa.getId() + " | " + pa.getName();
>>> }
>>>
>>> return result;
>>> }
>>>
>>> /**
>>> * Web service operation
>>> */
>>> @WebMethod(operationName = "test2")
>>> public String test2() {
>>> Parent parent = pfr.find(new Integer(2));
>>> String result = "|" +parent.getId() + "-" + parent.getName() +
>>> "|";
>>>
>>> Child child = new Child();
>>> child.setName("Child1");
>>> child.setParent(parent);
>>> cfr.create(child);
>>>
>>> @SuppressWarnings("unchecked")
>>> List<Child> childList = cfr.findAll();
>>> for(Child child2 : childList) {
>>> parent.getChilds().add(child2);
>>> }
>>> pfr.edit(parent);
>>>
>>> Parent parent2 = pfr.find(new Integer(2));
>>> result += "|PARENT2:" +parent.getId() + "-" + parent.getName() +
>>> "|";
>>> result += "CHILD:";
>>> for(Child c : parent2.getChilds()) {
>>> result += "c:" + c.getId() + "-" + c.getName();
>>> }
>>> return result;
>>> }
>>>
>>> /**
>>> * Web service operation
>>> */
>>> @WebMethod(operationName = "getParent2")
>>> public Parent getParent2(@WebParam(name = "id")
>>> Integer id) {
>>> Parent parent = pfr.find(id);
>>> return parent;
>>> }
>>>
>>> /**
>>> * Web service operation
>>> */
>>> @WebMethod(operationName = "getParent1")
>>> public String getParent1(@WebParam(name = "id")
>>> Integer id) {
>>> Parent parent = pfr.find(id);
>>> String r = "|" + parent.getId() + "-" + parent.getName();
>>> for(Child child : parent.getChilds()) {
>>> r += "" + child.getId() + "|" + child.getName() + "<br>";
>>> }
>>> return r;
>>> }
>>>
>>> }
>>>
>>>
>>> @Entity
>>> public class Parent implements Serializable {
>>> private static final long serialVersionUID = 1L;
>>> private Integer id;
>>>
>>> private String name;
>>>
>>> private List<Child> childs;
>>>
>>> public void setId(Integer id) {
>>> this.id = id;
>>> }
>>>
>>> @Id
>>> @GeneratedValue(strategy = GenerationType.AUTO)
>>> public Integer getId() {
>>> return id;
>>> }
>>>
>>> @OneToMany(cascade = CascadeType.ALL, mappedBy = "parent", fetch =
>>> FetchType.EAGER)
>>> public List<Child> getChilds() {
>>> return childs;
>>> }
>>>
>>> public void setChilds(List<Child> childs) {
>>> this.childs = childs;
>>> }
>>>
>>> public String getName() {
>>> return name;
>>> }
>>>
>>> public void setName(String name) {
>>> this.name = name;
>>> }
>>>
>>>
>>> }
>>>
>>>
>>> @Entity
>>> public class Child implements Serializable {
>>> private static final long serialVersionUID = 1L;
>>> private Integer id;
>>>
>>> String name;
>>>
>>> Parent parent;
>>>
>>> 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;
>>> }
>>>
>>> @ManyToOne
>>> @JoinColumn(name = "parent_id")
>>> public Parent getParent() {
>>> return parent;
>>> }
>>>
>>> public void setParent(Parent parent) {
>>> this.parent = parent;
>>> }
>>>
>>> }
>>>
>>>
>>>
>>>
>>>
>>>
>>> James Sutherland wrote:
>>>
>>>
>>>> What errors do you get?
>>>>
>>>> Please include stack trace and what you did to get the error.
>>>>
>>>> ---
>>>> http://wiki.java.net/bin/view/People/JamesSutherland James Sutherland
>>>>
>>>>
>>>> kriskross wrote:
>>>>
>>>>
>>>>> Hi.
>>>>> I have not bin able to solve this problem.
>>>>> It's all about @OneToMany - @ManyToOne relations in entitys.
>>>>> As long as I use my entitys in a session bean, there is no problem.
>>>>> But, when I try to use them as objects in a webservice I'll get plenty
>>>>> of
>>>>> errors.
>>>>> I've tried serveral methods with @XmlRootElement and @XmlTransient with
>>>>> no luck.
>>>>>
>>>>> Using the webservice I'm able to create objects, connect objects, but
>>>>> when I try to recive an object from the db it allways gives errors.
>>>>>
>>>>> So, if you have anything, any tips or other questions, please let me
>>>>> know. I've bin strugling with this for over a year now.
>>>>>
>>>>> Best Regards
>>>>> Kristian
>>>>>
>>>>>
>>>>> Marina Vatkina wrote:
>>>>>
>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> Did you solve your problem? If not, can you please explain what does
>>>>>> it
>>>>>> mean
>>>>>> "does not set any Produkt"?
>>>>>>
>>>>>> thanks,
>>>>>> -marina
>>>>>>
>>>>>> kriskross wrote:
>>>>>>
>>>>>>
>>>>>>> Hi
>>>>>>> Hope someone can helpe me. I'm stuck here.Having two objects:
>>>>>>>
>>>>>>> @XmlRootElement
>>>>>>> @Entity
>>>>>>> public class Produkt implements Serializable {
>>>>>>>
>>>>>>> @Id
>>>>>>> @GeneratedValue(strategy = GenerationType.SEQUENCE, generator =
>>>>>>> "Produkt_id_seq")
>>>>>>> private Integer id;
>>>>>>> ...
>>>>>>> @XmlElement(name = "varelagers")
>>>>>>> @OneToMany(cascade = CascadeType.ALL, mappedBy = "produkt", fetch
>>>>>>> =
>>>>>>> FetchType.EAGER)
>>>>>>> private List<Varelager> varelagers;
>>>>>>>
>>>>>>> public List<Varelager> getVarelager() {
>>>>>>> return this.varelagers;
>>>>>>> }
>>>>>>> ..
>>>>>>> }
>>>>>>>
>>>>>>>
>>>>>>> and
>>>>>>> @Entity
>>>>>>> public class Varelager implements Serializable {
>>>>>>> @Id
>>>>>>> @GeneratedValue(strategy = GenerationType.SEQUENCE, generator =
>>>>>>> "Varelager_id_seq")
>>>>>>> private Integer id;
>>>>>>>
>>>>>>> ......
>>>>>>>
>>>>>>> @ManyToOne
>>>>>>> @JoinColumn(name = "produkt_id")
>>>>>>> private Produkt produkt;
>>>>>>>
>>>>>>> @ManyToOne
>>>>>>> @JoinColumn(name = "storelse_id")
>>>>>>> private Storelse storelse;
>>>>>>>
>>>>>>> public Produkt getProdukt() {
>>>>>>> return produkt;
>>>>>>> }
>>>>>>>
>>>>>>> public void setProdukt(Produkt produkt) {
>>>>>>> this.produkt = produkt;
>>>>>>> }
>>>>>>> }
>>>>>>>
>>>>>>> I've created an webservice that exposes both produkt and varelager.
>>>>>>> And I'm trying to add a "varelager" to "produkt", using the
>>>>>>> webservice.
>>>>>>> But here my objects does not have all the same methods.
>>>>>>> I'm missing Varelager.getProdukt(), and Varelager.setProdukt(Produkt
>>>>>>> produkt).
>>>>>>>
>>>>>>> Anyone who can tell me why??
>>>>>>>
>>>>>>>
>>>>>>> I've allso tried this as a workarround
>>>>>>> Produkt p = webservice.getproddukt(new Integer(1));
>>>>>>> Varelager vl = new Varelager();
>>>>>>> vl = webservice.createVarelager(vl);
>>>>>>> p.getVarelagers().add(vl);
>>>>>>> webservice.editProdukt(p);
>>>>>>>
>>>>>>> This creates the varelager object, but does not set any Produkt.
>>>>>>> Any other way?
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>
>