2 Replies Latest reply on Jul 16, 2008 5:11 PM by Hugh Buchanan

    Cyclic web services

    Ryan Carmichael Newbie

      Let's say I have a web service called getVehicle(int vehicleId) and I'm expecting it to return me a Vehicle object.

      If Vehicle has a java.util.Set of Wheel objects, and the Wheel object has a reference to its owner (Vehicle), then obviously there is an issue here when trying to persist to XML because of this bidirectional relationship.

      My goal is to have JBoss host this web service, and then use wsimport to create the stub files for the client to use. This part works fine, except the server throws an error when it goes to marshal the object:

      Caused by: com.sun.istack.SAXException2: A cycle is detected in the object graph. This will cause infinitely deep XML: org.test.Vehicle@13c6308 -> org.test.Wheel@15880be -> org.test.Vehicle@13c6308

      I have read (and hopefully understand) https://jaxb.dev.java.net/guide/Mapping_cyclic_references_to_XML.html but I don't think it applies in this case because wsimport will be creating the stubs for me.

      Is there any way to get this going? I'm guessing I will have to fall back to my last resort, which is making Wheel only have a reference to the Vehicle's ID instead of the Vehicle object.


        • 1. Re: Cyclic web services
          Thomas Diesler Master

          Yes, this article does apply to you. You need to annotate the JAXB classes you intend to be the payload. You can then use wsprovide to provide the abstract contract (i.e. wsdl+schema)

          On the client side you can reuse the JAXB classes. You can use wsconsume to generate the SEI from the wsdl.

          • 2. Re: Cyclic web services
            Hugh Buchanan Newbie

            I'm having the same problem and can't seem to get the correct annotations into my EJB to resolve this.

            I'm using a very simple web service and performing a findAll() to test.

            Can I not use the entity classes for this? Can anyone show any examples for the xml annotations to drive the traversal? The annotations I've inserted haven't gotten me past this exception.