3

enter code hereHi Guys me and some classmates are working on a project for school and are stuck with this error: a cycle is detected in the object graph this will cause infinitely deep xml.

This is our code

@Entity
public class Client extends User implements Serializable {
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date birthdate;
    private String address;
    private String zipcode;
    private String city;
    private String phone;
    private String info;
    private boolean active;
    @OneToMany(mappedBy = "client")
    private List<Cartrack> cartrac

And this is our cartrack object:

@Entity
public class Cartrack implements Serializable {

    @Id
    private String id;
    @OneToOne(  mappedBy = "cartrack", 
                cascade = CascadeType.ALL,
                fetch = FetchType.EAGER
            )
    private Vehicle vehicle;
    @ManyToOne
    private Client client;

And last but not least the vehicle object:

@Entity
public class Vehicle implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String licenseNr;
    private boolean stolen;
    @OneToOne
    private Cartrack cartrack;

All object have their setters and getters, and still after hours of research and reading tons of documentation we're still unable to fix the problem.

Our last hope is Stackoverflow!

Thanks in advance!

Bart Pasmans
  • 135
  • 1
  • 3
  • 7
  • and what are you actually doing with those objects ? and where does XML come into it ? those classes presumably can be persisted by JPA perfectly well (otherwise you'd be showing an exception). – DataNucleus Apr 17 '13 at 13:44
  • We are using SOAP to communicate the objects from a service side to a client side – Bart Pasmans Apr 17 '13 at 13:59
  • so the problem isn't JPA (and your JPA implementation) then, and more of you passing those objects into SOAP and how SOAP is creating XML and how to delimit it. Suggest you possibly remove the JPA tag then (since that works), and also provide a stack trace of your exception/error in the question – DataNucleus Apr 17 '13 at 15:22
  • Check out the `@XmlInverseReference` extension in EclipseLink JAXB (MOXy) - http://blog.bdoughan.com/2013/03/moxys-xmlinversereference-is-now-truly.html. If your are deploying your web services to Weblogic 12.1.1 MOXy is the default JAXB provider. If you are using GlassFish 3.1.2 the following will help - http://blog.bdoughan.com/2012/02/glassfish-312-is-full-of-moxy.html, for all other app servers see: http://blog.bdoughan.com/2013/02/leveraging-moxy-in-your-web-service-via.html – bdoughan Apr 19 '13 at 04:31

1 Answers1

0

Problem solved.

We had a bidirectional relationship which apprently XML could not handle the right way we needed. So this could be seen more as a human error because the relationship was not needed.

By removing this relationship SOAP was able again to send the data.

Thanks for thinking with us!

Bart Pasmans
  • 135
  • 1
  • 3
  • 7