Jaxb Bidirectional Relationship Mapping
I have List<SelectConditionHeaderModel>
.
When I sort this list, I get an error:
javax.xml.bind.MarshalException
- with linked exception:
[com.sun.istack.internal.SAXException2: A cycle is detected in the object graph. This will cause infinitely deep XML
My abstract parent class.
@XmlRootElement
@XmlSeeAlso({ SelectConditionHeaderModel.class,
SelectConditionModel.class })
public abstract class SelectConditionParentModel {
@XmlInverseReference(mappedBy = "conditionList")
SelectConditionParentModel parent;
public SelectConditionParentModel getParent() {
return parent;
}
public void setParent(HbaseSelectConditionParentModel parent) {
this.parent = parent;
}
}
Header class extending abstract parent element
@XmlRootElement
public class SelectConditionHeaderModel extends
SelectConditionParentModel {
List<SelectConditionParentModel> conditionList;
String header;
public List<SelectConditionParentModel> getConditionList() {
return conditionList;
}
public void setConditionList(List<SelectConditionParentModel> condition) {
this.conditionList = condition;
}
public String getHeader() {
return header;
}
public void setHeader(String header) {
this.header = header;
}
}
A condition class that extends an abstract parent element
@XmlRootElement
public class SelectConditionModel extends SelectConditionParentModel {
String tableName;
public String getTableName() {
return columnFamily;
}
public void setTableName(String tableName) {
this.tableName = tableName;
}
}
Please help me with this. I also used XMLInverseReference, but it doesn't seem to work.
Try this config based on @XmlID and @XmlIDREF.
or you can put @XmlTransient to exclude the subgraph.
If you are using EclipseLink JAXB (MOXy) as your JAXB provider (JSR-222), you can use our extension @XmlInverseReference
to map bi-directional relationships.
You can find a complete example on my blog:
- http://blog.bdoughan.com/2013/03/moxys-xmlinversereference-is-now-truly.html
I offer you this solution .. I had the same problem but solved @XmlTransient.
I hope to help you.