[Solution] JAXB Infinitely cycling bidirectional relationship
While we trying to create bidirectional relationship we may get an error which is about infinitely cycling.
These errors can be like that:
If we are using webservice, our client can get error like:
A cycle is detected in the object graph. This will cause infinitely deep XML
Or we can get error in our server logs like:
javax.xml.ws.WebServiceException: javax.xml.bind.MarshalException – with linked exception: [com.sun.istack.internal.SAXException2: A cycle is detected in the object graph. This will cause infinitely …..
We should use @XmlTransient annotion to break this cycle easly.
So, as you see we have two class. AutoCategory and AutoSubCategory. They have bidirectional OneToMany relationship. And we are try to getting categoryid for AutoSubCategory class. And both classes has relationship with Auto class. We should send our categoryid and subcategory to Auto Class. But when we create the relationship we should put @XmlTransient annotion to each getAuto method. Because we have to break cycle we didn’t get infinitely cycling.