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

只谈情不闲聊 提交于 2019-12-04 16:21:36

I'm not sure if this is possible, but try the element, maybe it has a 'schema' attribute, sadly it's not that well documented.

Regards, Stefan

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

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

    <!-- try this -->
    <hj:entity>
        <orm:table name="item"/>
    </hj:entity>
</jaxb:bindings>

Source: http://confluence.highsource.org/display/HJ3/Customization+Guide

Author of here.

See @Stefan's answer, just add the schema="schema_name" attribute:

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

orm:table is actually a JPA XML element so that's documented in the JPA spec. :)

See this schema:

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

I'm basically not inventing anything here.

You don't need JAXB2 Annotate Plugin for that, this works OOTB.

Here's an issue for the global prefix:

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

Unresolved yet. Can be solved via custom naming now, but that's quite awkward.

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

I agree, it would be nice to make it configurable.

Update How to do this globally:

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

But you'll also need to customize defaults for associations and so on. See he built-in defaults here:

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

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

You may also define a schema for all entities globally in orm file referenced from persistence.xml. There is no need to copy schema into every @Table annotation.

persistence.xml:

...
  <persistence-unit name="MySchemaPU"  transaction-type="JTA">
     <mapping-file>META-INF/orm.xml</mapping-file>

And an orm.xml in META-INF folder:

<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd"
                 version="1.0">
 <persistence-unit-metadata>

  <persistence-unit-defaults>
   <schema>schema_name</schema>
  </persistence-unit-defaults>
 </persistence-unit-metadata>
</entity-mappings
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!