javahibernatejaxbhyperjaxb

Customize element for abstract complexType with HyperJaxb3


I'm converting an XSD schema to a Java annotated bean for Hibernate with HyperJaxb3.

So far I managed to generate the Java objects, but I need to customize the remark field of the OperableType because the default generated length is 255 and I need to extend it to 4000.

Here's the fragment of the relevent xsd schema:

<xs:complexType name="OperableType" abstract="true">
    <xs:annotation>
        <xs:documentation xml:lang="en">OperableType contains all the elements and attributes common to all the operables. This is an abstract type, so no element of this type will be present in the XML.
        The logical ID is a unique logical identifier of a sanctioned entity, of a regulation or of a detail of a sanction entity. This information is also provided to external actors for help, especially when entity multiple aliases make it difficult the identification task. For entities imported from previous database, the old value is retained.</xs:documentation>
    </xs:annotation>
    <xs:sequence>
        <xs:element name="remark" type="fsdexport:UnlimitedTextType" minOccurs="0" maxOccurs="unbounded"/>
        <xs:element name="additionalInformation" type="fsdexport:AdditionalInfoType" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
    <xs:attribute name="logicalId" type="xs:long" use="required"/>
</xs:complexType>
<xs:simpleType name="UnlimitedTextType">
    <xs:restriction base="xs:string"/>
</xs:simpleType>

I can't modify the XSD schema nor the XML file I receive, so I need to customize the bindings for it to work.

I tried using this binding

    <jxb:bindings node="xs:complexType[@name='OperableType']">
        <jxb:bindings node="xs:sequence//xs:element[@name='remark']">
            <hj:basic>
                <orm:column length="4000" />
            </hj:basic>
        </jxb:bindings>
    </jxb:bindings>

but it doesn't modify the length in the generated code.

@ElementCollection
@OrderColumn(name = "HJINDEX")
@Column(name = "HJVALUE", length = 255)
@CollectionTable(name = "OPERABLE_TYPE_REMARK", joinColumns = {
    @JoinColumn(name = "HJID")
})
public List<String> getRemark() {

I also tried to use 'hj:default-single-property' to customized the UnlimitedTextType but I didn't managed to make it work either.


Solution

  • After asking from help from the source, https://github.com/highsource/hyperjaxb3/issues/54, I have the answer:

    <jxb:bindings node="xs:complexType[@name='OperableType']">
        <jxb:bindings node="xs:sequence//xs:element[@name='remark']">
            <hj:element-collection>
                <orm:column length="4000" />
            </hj:element-collection>
        </jxb:bindings>
    </jxb:bindings>
    

    The key is tu use hj:element-collection instead of hj:basic for an xml sequence.