javahibernatexsdjaxbhyperjaxb

hyperjaxb Inline Customizations issue for ignoring hjid


I have the requirement to ignore the auto generated hjid in my JPA annotated java pojos. I can get this working using external binding, but when I try to do the same thing using JAXB Inline Customizations, it still create the hjid. What I am missing here.

Master.xsd

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns:hj="http://hyperjaxb3.jvnet.org/ejb/schemas/customizations"
        xmlns:orm="http://java.sun.com/xml/ns/persistence/orm">
        <xs:annotation>
            <xs:appinfo>
                <hj:persistence>
                    <hj:default-generated-id transient="true"
                        name="hjid" />
                </hj:persistence>
            </xs:appinfo>
        </xs:annotation>

        <xs:complexType name="master">

            <xs:sequence>
                <xs:element name="PLAYERID" type="xs:string">
                    <xs:annotation>
                        <xs:appinfo>
                            <hj:id>
                                <orm:column name="PLAYERID" />
                            </hj:id>
                        </xs:appinfo>
                    </xs:annotation>
                </xs:element>
                <xs:element name="BIRTHYEAR" type="xs:string" />
                <xs:element name="BIRTHMONTH" type="xs:string" />
                <xs:element name="BIRTHDAY" type="xs:string" />
                <xs:element name="BIRTHCOUNTRY" type="xs:string" />
                <xs:element name="BIRTHSTATE" type="xs:string" />
                <xs:element name="BIRTHCITY" type="xs:string" />
                <xs:element name="DEATHYEAR" type="xs:string" />
                <xs:element name="DEATHMONTH" type="xs:string" />
                <xs:element name="DEATHDAY" type="xs:string" />
                <xs:element name="DEATHCOUNTRY" type="xs:string" />
                <xs:element name="DEATHSTATE" type="xs:string" />
                <xs:element name="DEATHCITY" type="xs:string" />
                <xs:element name="NAMEFIRST" type="xs:string" />
                <xs:element name="NAMELAST" type="xs:string" />
                <xs:element name="NAMEGIVEN" type="xs:string" />
                <xs:element name="WEIGHT" type="xs:string" />
                <xs:element name="HEIGHT" type="xs:string" />
                <xs:element name="BATS" type="xs:string" />
                <xs:element name="THROWS" type="xs:string" />
                <xs:element name="DEBUT" type="xs:string" />
                <xs:element name="FINALGAME" type="xs:string" />
                <xs:element name="RETROID" type="xs:string" />
                <xs:element name="BBREFID" type="xs:string" />
                <xs:element name="IMAGE" type="xs:string" />
            </xs:sequence>
        </xs:complexType>
    </xs:schema>

External bindds which works but I need to avoid using external bindings bindings.xjb

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings
    version="2.1"
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:orm="http://java.sun.com/xml/ns/persistence/orm"
    xmlns:hj="http://hyperjaxb3.jvnet.org/ejb/schemas/customizations">

    <jaxb:bindings schemaLocation="master.xsd" node="/xs:schema">
        <hj:persistence>
            <hj:default-generated-id transient="true" name="Hjid"/>
        </hj:persistence>
    </jaxb:bindings>

</jaxb:bindings>

Solution

  • That looks fine, but you may need to declare:

    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:hj="http://hyperjaxb3.jvnet.org/ejb/schemas/customizations"
    xmlns:orm="http://java.sun.com/xml/ns/persistence/orm"
    
    jaxb:extensionBindingPrefixes="hj orm"
    jaxb:version="2.1"
    

    on your schema.

    See this example:

    <xs:complexType name="four">
        <xs:sequence>
            <xs:element name="id" type="xs:int" minOccurs="0">
                <xs:annotation>
                    <xs:appinfo>
                        <hj:id>
                            <orm:column name="FOUR_CUSTOM_ID"/>
                            <orm:generated-value strategy="SEQUENCE" generator="four-sequence"/>
                            <orm:sequence-generator name="four-sequence" sequence-name="FOUR_SEQ"/>
                        </hj:id>    
                    </xs:appinfo>
                </xs:annotation>
            </xs:element>
            <xs:element name="value" type="xs:string" minOccurs="0"/>
        </xs:sequence>
    </xs:complexType>
    

    This is pretty the same thing you're already doing. Only that you might be missing jaxb:extensionBindingPrefixes="hj orm".