0

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.

1 Answers1

1

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>
Suken Shah
  • 1,622
  • 14
  • 20
  • Thanks, but I've already tried those, and it didn't work. I've just seen that the XML code that I had put in the question isn't showing up. I'll try to fix that. To be clear, I'm trying to use an id field in a *superclass*, and not trying to make one of the fields in the generated classes the id. I've set up the bindings.xjb file to make all generated classes children of DataObject, which has the ID field. – Hans de Ruiter May 16 '15 at 01:07