为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

摇曳的蔷薇 2022-07-27 11:26:14
我正在将 XSD 模式转换为带有 HyperJaxb3 的 Hibernate 的 Java 注释 bean。到目前为止,我设法生成了 Java 对象,但是我需要自定义 OperableType 的备注字段,因为默认生成的长度是 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,但我也没有设法让它工作。
查看完整描述

1 回答

?
倚天杖

TA贡献1828条经验 获得超3个赞

从源头寻求帮助后, 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-collection 而不是 hj:basic 作为 xml 序列。


查看完整回答
反对 回复 2022-07-27
  • 1 回答
  • 0 关注
  • 180 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号