简体   繁体   中英

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). So far I've managed to get it to generate classes that are descendants of DataObject using the following in the bindings.xjb file:

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

So, how do I stop Hyperjaxb3 from generating hjid for all classes? 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. 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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