使用 HyperJaxb3 自定义抽象复杂类型的元素

Customize element for abstract complexType with HyperJaxb3

我正在将一个 XSD 模式转换为一个 Java 用于 Hibernate with HyperJaxb3 的注释 bean。

至此我成功生成了Java个对象,但是我需要自定义OperableType的remark字段,因为默认生成的长度是255,我需要扩展到4000。

这是相关 xsd 架构的片段:

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

我无法修改 XSD 架构,也无法修改我收到的 XML 文件,因此我需要自定义绑定才能正常工作。

我试过使用这个绑定

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

但它不会修改生成代码中的长度。

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

我也尝试过使用 'hj:default-single-property' 自定义 UnlimitedTextType,但我也没有成功。

向源头求助后, https://github.com/highsource/hyperjaxb3/issues/54,我有答案:

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

关键是要使用 hj:element 集合而不是 hj:basic 作为 xml 序列。