mavenjpaxsdjaxbhyperjaxb

Editing @java.persitence.Table in external jaxb-Binding


I've set up a maven project to generate Java classes from a xsd-Schema. Firstly I configured the maven-hyperjaxb3-plugin (see the pom.xml snippet below), so that it can put the default JPA2 annotations in the entities. One of this annotations is @java.persitence.Table(name = "table_name"). I want to extend this annotation through an external global binding so that I can put the name of schema in it too. So that I would get @java.persitence.Table(name = "table_name", schema = "schema_name"). Is there a way to do this? What about globally putting a prefix in the name of the table: @java.persitence.Table(name = "prefix_table_name"), any ideas how to do that?

Regards Erzen

pom.xml snippet

<groupId>org.jvnet.hyperjaxb3</groupId>
<artifactId>maven-hyperjaxb3-plugin</artifactId>
<version>0.6.0</version>
<executions>
    <execution>
        <goals>
            <goal>generate</goal>
        </goals>
    </execution>
</executions>
<configuration>
    <variant>jpa2</variant>
    <extension>true</extension>
    <roundtripTestClassName>EKMSEnvelopeRoundtripTest</roundtripTestClassName>
    <args>
        <arg>-Xinheritance</arg>
        <arg>-XtoString</arg>
        <arg>-Xannotate</arg>
    </args>
    <schemaExcludes>
        <exclude>ekvaattributes.xsd</exclude>
    </schemaExcludes>
</configuration>

bindings-xjc.xjb snippet

<jaxb:globalBindings localScoping="toplevel">
    <!-- JPA-entities must be serializable -->
    <xjc:serializable />
</jaxb:globalBindings>


<jaxb:bindings schemaLocation="schema.xsd"
    node="/xs:schema">

    <annox:annotate>
        <!-- my attempt -->
        <annox:annotate annox:class="javax.persistence.Table"
            schema="schema_name">
        </annox:annotate>
    </annox:annotate>

    <hj:persistence>
        <hj:default-generated-id name="Hjid">
            <orm:generated-value strategy="IDENTITY" />
        </hj:default-generated-id>
    </hj:persistence>
</jaxb:bindings>

Solution

  • @lexicore Thnx for the help. After putting your suggestion in the right context it worked.

        <hj:persistence>
            <hj:default-entity>
                <!-- no need to overwrite the default generated table names-->
                <orm:table schema="schema_name" />
            </hj:default-entity>
        </hj:persistence>