【问题标题】:JAXB Marshalling - Reference is pulling and inserting entire object details inside XMLJAXB Marshalling - 参考是在 XML 中提取和插入整个对象详细信息
【发布时间】:2014-12-08 19:59:59
【问题描述】:

我正在尝试执行 JAXB 编组并遇到奇怪的问题。我在一个名为 Column、Row 和 Table 的 xml 中有三个对象

table 元素引用了列 ID 和行 ID。在 Hibernate 中,我映射了一对一的关系(通过多对一关系))

当我生成 xml 时,我看到整个记录详细信息标签代替 ID 被插入到我的 xml 中。

我想要什么:

<Hierarchy name="" desc="" title="" >
    <Column>
         <Column name="" desc="" group="" id=""/>
    </Column>
    <Row>
        <Row id =1 name=" " desc="" id="">
           <Row id = 2 name="" desc="" id="" />
        </Row>
        <Row id = 3 name=" " desc="" id="" />
    </Rows>
    <table>
         <table name="" RowID="" measureID="" filter="" expression="" product="" dataset="" datatype="" subreport="" />
    </table>
</Hierarchy>

我得到了什么

<Hierarchy name="" desc="" title="" >
    <Column>
         <Column name="" desc="" group="" id=""/>
    </Column>
    <Row>
        <Row id =1 name=" " desc="" id="">
           <Row id = 2 name="" desc="" id="" />
        </Row>
        <Row id = 3 name=" " desc="" id="" />
    </Rows>
    <table>
         <table name=""  filter="" expression="" product="" dataset="" datatype="" subreport="" 
         <name =""/>
         <RowID>
            <id>1</id>
            <name></name>
            <desc></desc>
        </RowID>
        <measureID>
            <id>1</id>
            <name></name>
            <desc></desc>
         </table>
..............
    </table>
</Hierarchy>

我在我的休眠映射文件中定义了以下关系

 <many-to-one name="RowID" column="RowName" 
    class="com.abc.Row" cascade="save-update" lazy="false" not-null="false"></many-to-one>

<many-to-one name="ColumnID" column="ColumnName" 
    class="com.abc.Column" cascade="save-update" lazy="false" not-null="false"></many-to-one> 

在课堂上我将关系定义为

public class Table{
private id;
private Row rowID;
Private Column columnID;

..getters/setters
}

由于我是 JAXB 的新手,请有人给我建议

【问题讨论】:

    标签: java xml reference jaxb marshalling


    【解决方案1】:

    @XmlID 注释你的Row.id 属性,用@XmlIDREF 注释你的Table.rowID 属性。

    【讨论】:

    • 我尝试使用 XMLID 和 XmlIDREF 进行注释。但我的 id 是 int 数据类型,而 XMLID 期望它是字符串数据类型。在我的数据库中,我们有 ID 的 int 列。
    • @Sam weblogs.java.net/blog/2005/08/15/… 或转换成额外的 getter/setter 或尝试额外的 @XmlAdapter
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-20
    相关资源
    最近更新 更多