简体   繁体   English

Hyperjaxb3:如何使用超类的ID?

[英]Hyperjaxb3: How do I get it to use a superclass' id?

I'm trying to generate a set of Java classes from *.xsd files that all have a common mapped-super-class (called DataObject). 我正在尝试从* .xsd文件生成一组Java类,这些文件都具有一个公共的映射超类(称为DataObject)。 So far I've managed to get it to generate classes that are descendants of DataObject using the following in the bindings.xjb file: 到目前为止,我已经设法在bindings.xjb文件中使用以下内容来生成DataObject的后代类:

  <jaxb:globalBindings localScoping="toplevel"> <xjc:superClass name="com.companyname.model.DataObject"/> <jaxb:serializable uid="1" /> </jaxb:globalBindings> 

My problem is that Hyperjaxb3 generates its own primary key called hjid, but DataObject already contains a primary key and I need/want to use that. 我的问题是Hyperjaxb3生成了自己的称为hjid的主键,但是DataObject已经包含一个主键,我需要/想要使用它。

So, how do I stop Hyperjaxb3 from generating hjid for all classes? 那么,如何停止Hyperjaxb3为所有类生成hjid? I've already tried various suggestions that I've found online, but they didn't work for me. 我已经尝试过在网上找到的各种建议,但是它们对我没有用。

You or mark one of existing properties as identifier property using the hj:id customization element. 您可以使用hj:id自定义元素将现有属性之一标记为标识符属性。 See following: 请参阅以下内容:

<xs:complexType name="myType">
    <xs:sequence>
        <!-- ... -->
        <xs:element name="id" type="xs:int" minOccurs="0">
            <xs:annotation>
                <xs:appinfo>
                    <hj:id>
                        <orm:column name="MY_ID"/>
                        <orm:generated-value strategy="SEQUENCE" generator="my-sequence"/>
                        <orm:sequence-generator name="my-sequence" sequence-name="MY_SEQ"/>
                    </hj:id> 
                </xs:appinfo>
            </xs:annotation>
        </xs:element>
        <!-- ... -->
    </xs:sequence>
</xs:complexType>

OR 要么

<xs:element name="id" type="xs:int" minOccurs="0">
    <xs:annotation>
        <xs:appinfo>
            <hj:id/>
        </xs:appinfo>
    </xs:annotation>
</xs:element>

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

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