maven - 在外部 jaxb-Binding 中编辑 @java.persistence.Table

标签 maven jpa xsd jaxb hyperjaxb

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

问候 埃尔森

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

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

最佳答案

的作者在这里。

查看@Stefan的回答,只需添加schema="schema_name"属性:

<orm:table name="item" schema="schema_name"/>

orm:table 实际上是一个 JPA XML 元素,因此它记录在 JPA 规范中。 :)

查看此架构:

https://github.com/highsource/hyperjaxb3/blob/master/ejb/schemas/persistence/src/main/resources/persistence/orm/orm_1_0.xsd#L1814-L1815

我基本上没有在这里发明任何东西。

您不需要 JAXB2 Annotate Plugin,这可以正常工作。

这是全局前缀的问题:

http://jira.highsource.org/browse/HJIII-87

尚未解决。现在可以通过自定义命名来解决,但是比较尴尬。

https://github.com/highsource/hyperjaxb3/tree/master/ejb/tests/custom-naming

我同意,如果能将其配置为可配置就好了。

更新如何在全局范围内执行此操作:

<hj:default-entity>
    <orm:table name="item" schema="schema_name"/>
</hj:default-entity>

但是您还需要自定义关联的默认值等。在这里查看内置默认值:

https://github.com/highsource/hyperjaxb3/blob/master/ejb/plugin/src/main/resources/org/jvnet/hyperjaxb3/ejb/strategy/customizing/impl/DefaultCustomizations.xml

关于maven - 在外部 jaxb-Binding 中编辑 @java.persistence.Table,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32334881/

相关文章:

maven - Jenkins:当 Maven 构建发生在 Docker 容器中时如何使用 JUnit 插件

java - maven 使用 --add-exports 运行和构建

maven - Travis Maven 构建因 OutOfMemoryException 退出

java - 测试领​​域模型 Junit Java

java - Joincolumn 返回空值

unit-testing - Maven 不执行任何单元测试

java - 链式事务 api 调用 spring

Eclipse XSD 编辑器

c# - 使用 xsd.exe 生成 c# 文件,出现错误和警告

WPF TextBox不会更新源