0

我正在使用 hyperjaxb 从 XSD 文件生成带有 JAXB-JPA 注释的类。我有许多遭遇的角色实体。这是自定义部分

    <bindings node="xsd:complexType[@name='PersonaType']">
        <bindings node=".//xsd:element[@name='id']">
            <hj:id>
                <orm:generated-value strategy="AUTO"/>
            </hj:id>
        </bindings>
        <bindings node=".//xsd:element[@name='encounters']">
            <hj:one-to-many name="encountersRel">
                <orm:join-table name="PERSONA_ENCOUNTER">
                    <orm:join-column name="PERSONA_ID"/>
                    <orm:inverse-join-column name="ENCOUNTER_ID"/>
                </orm:join-table>
            </hj:one-to-many>
        </bindings>
    </bindings>

到目前为止,一切都很好。问题是,默认情况下,这会生成此映射

/**
 * Gets the value of the encounters property.
 * 
 * <p>
 * This accessor method returns a reference to the live list,
 * not a snapshot. Therefore any modification you make to the
 * returned list will be present inside the JAXB object.
 * This is why there is not a <CODE>set</CODE> method for the encounters property.
 * 
 * <p>
 * For example, to add a new item, do as follows:
 * <pre>
 *    getEncounters().add(newItem);
 * </pre>
 * 
 * 
 * <p>
 * Objects of the following type(s) are allowed in the list
 * {@link EncounterType }
 * 
 * 
 */
@OneToMany(targetEntity = EncounterType.class, cascade = {
    CascadeType.ALL
})
@JoinTable(name = "PERSONA_ENCOUNTER", joinColumns = {
    @JoinColumn(name = "PERSONA_ID")
}, inverseJoinColumns = {
    @JoinColumn(name = "ENCOUNTER_ID")
})
public List<EncounterType> getEncounters() {
    if (encounters == null) {
        encounters = new ArrayList<EncounterType>();
    }
    return this.encounters;
}

/**
 * 
 * 
 */
public void setEncounters(List<EncounterType> encounters) {
    this.encounters = encounters;
}

问题是我需要使用映射Set而不是List. 如何使用自定义来实现这一点?

4

1 回答 1

0

Hyperjaxb的作者在这里。

据我记得,目前还没有这样的功能。

我可以想象一个 XJC 插件可以做到这一点,但我现在还不知道。

也可以看看:

JAXB - 将元素绑定到 Set 而不是 List

于 2015-12-16T10:01:24.977 回答