简体   繁体   English

Jaxb映射双向关系

[英]Jaxb Mapping Bidirectional Relationship

I have a List<SelectConditionHeaderModel> . 我有一个List<SelectConditionHeaderModel>

When i am marshalling this list, I am getting 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 the abstract parent Header类扩展抽象父级

@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;
    }

}

Condition class extending the Abstract Parent 条件类扩展抽象父级

@XmlRootElement
public class SelectConditionModel extends SelectConditionParentModel {

    String tableName;


    public String getTableName() {
        return columnFamily;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

}

Please help me out with this . 这个你能帮我吗 。 I have also used XMLInverseReference but it seems that it is not working. 我也使用过XMLInverseReference,但它似乎无法正常工作。

Try to use this configuration based on @XmlID and @XmlIDREF. 尝试使用基于@XmlID和@XmlIDREF的配置

or you can put @XmlTransient to exclude the subgraph. 或者你可以放@XmlTransient来排除子图。

If you are using EclipseLink JAXB (MOXy) as your JAXB (JSR-222) provider then you can leverage our @XmlInverseReference extension to map your bi-directional relationship. 如果您使用EclipseLink JAXB(MOXy)作为JAXB(JSR-222)提供程序,那么您可以利用我们的@XmlInverseReference扩展来映射您的双向关系。

You can find a complete example on my blog: 您可以在我的博客上找到完整的示例:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM