0

I am using hyperjaxb to generate JAXB-JPA annotated classes from a XSD file. I have Persona entity with many Encounters. This is the customization section

    <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>

So far so good. The problem is that, by default, this generates this mapping

/**
 * 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;
}

The problem is I need the mapping to use Set instead of List. How do I achieve this using customizations?

Xstian
  • 8,184
  • 10
  • 42
  • 72
Alfredo A.
  • 1,697
  • 3
  • 30
  • 43

1 Answers1

0

Author of Hyperjaxb here.

As far as I remember, there is no such feature at the moment.

I can imagine an XJC plugin which does this, but I'm not aware of it at the moment.

See also:

JAXB - Binding element to Set instead of List

Community
  • 1
  • 1
lexicore
  • 42,748
  • 17
  • 132
  • 221