在外部jaxb-Binding中编辑@ java.persitence.Table [英] Editing @java.persitence.Table in external jaxb-Binding

查看:132
本文介绍了在外部jaxb-Binding中编辑@ java.persitence.Table的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了一个maven项目来从xsd-Schema生成Java类。首先,我配置了maven-hyperjaxb3-plugin(参见下面的pom.xml片段),以便它可以在实体中放置默认的JPA2注释。其中一个注释是@ java.persitence.Table(name =table_name)。我想通过外部全局绑定扩展此注释,以便我也可以将schema的名称放在其中。所以我会得到@ java.persitence.Table(name =table_name,schema =schema_name)。有没有办法做到这一点?
全局在表名中添加前缀怎么样:@ java.persitence.Table(name =prefix_table_name),任何想法怎么做?

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?

问候
Erzen

Regards Erzen

pom.xml片段

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


推荐答案

@lexicore Thnx的帮助。在适当的背景下提出你的建议后,它就有效了。

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

这篇关于在外部jaxb-Binding中编辑@ java.persitence.Table的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆