繁体   English   中英

使用HyperJaxb3自定义抽象complexType的元素

[英]Customize element for abstract complexType with HyperJaxb3

我正在使用HyperJaxb3将XSD模式转换为Hibernate的Java注释的Bean。

到目前为止,我设法生成了Java对象,但是我需要自定义OperableType的备注字段,因为默认的生成长度为255,并且需要将其扩展为4000。

这是relevent 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>

关键是对于XML序列,请使用hj:element-collection代替hj:basic。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM