如何使用 eclipselink-orm.xml 文件覆盖而不是替换 orm.xml 文件中的某些元素?
How do I override, not replace, certain elements in an orm.xml file with an eclipselink-orm.xml file?
page documenting the eclipselink-orm.xml
file 部分表示:
This mapping file can be used in place of JPA's standard mapping file or can be used to override a JPA mapping file.
我有兴趣做后者,而不是前者。
因此,我将以下内容放入 META-INF/persistence.xml
文件中:
<mapping-file>META-INF/my-orm.xml</mapping-file>
<mapping-file>META-INF/my-eclipselink-orm.xml</mapping-file>
他们捡起来很好。
现在请注意,我不希望 my-eclipselink-orm.xml
的内容成为 my-orm.xml
内容的超集。我只想在其中添加最低限度的 XML 以(语义上)将某些特定于 EclipseLink 的功能添加到 my-orm.xml
.
中指定的给定映射
现在假设我在 my-orm.xml
中有一个名为 names
的 <one-to-many>
映射。 (基本的,基本的东西。)
假设现在 my-eclipselink-orm.xml
我想在语义上将 <batch-fetch>
元素添加到该映射。
如果我这样做:
<entity class="the.entity.class.in.Question">
<attributes>
<one-to-many name="names">
<batch-fetch size="10" type="JOIN"/>
</one-to-many>
</attributes>
</entity>
...然后 EclipseLink 对我大喊大叫:
Conflicting XML elements [<one-to-many>] with the same name [names] were found. The first was found in the mapping file [file:/Users/ljnelson/Projects/foo/target/classes/META-INF/my-eclipselink-orm.xml] and the second in the mapping file [file:/Users/ljnelson/Projects/foo/target/classes/META-INF/my-real-orm.xml]. Named XML elements must be unique across the persistence unit.
那么如何用 eclipselink-orm.xml
覆盖 仅 "real" orm.xml
的某些部分 ?
这种情况包含在示例 6-4 中:
http://www.eclipse.org/eclipselink/documentation/2.6/jpa/extensions/schema.htm
因为 my-eclipselink-orm.xml 被显式列出,所以它被视为 JPA orm.xml 文件。您需要将文件重命名为 eclipselink-orm.xml 并从 persistence.xml 中删除标记,以便您的情况与示例 6-3 匹配。文档声明它应该合并映射,但示例在这一点上并不清楚。
page documenting the eclipselink-orm.xml
file 部分表示:
This mapping file can be used in place of JPA's standard mapping file or can be used to override a JPA mapping file.
我有兴趣做后者,而不是前者。
因此,我将以下内容放入 META-INF/persistence.xml
文件中:
<mapping-file>META-INF/my-orm.xml</mapping-file>
<mapping-file>META-INF/my-eclipselink-orm.xml</mapping-file>
他们捡起来很好。
现在请注意,我不希望 my-eclipselink-orm.xml
的内容成为 my-orm.xml
内容的超集。我只想在其中添加最低限度的 XML 以(语义上)将某些特定于 EclipseLink 的功能添加到 my-orm.xml
.
现在假设我在 my-orm.xml
中有一个名为 names
的 <one-to-many>
映射。 (基本的,基本的东西。)
假设现在 my-eclipselink-orm.xml
我想在语义上将 <batch-fetch>
元素添加到该映射。
如果我这样做:
<entity class="the.entity.class.in.Question">
<attributes>
<one-to-many name="names">
<batch-fetch size="10" type="JOIN"/>
</one-to-many>
</attributes>
</entity>
...然后 EclipseLink 对我大喊大叫:
Conflicting XML elements [<one-to-many>] with the same name [names] were found. The first was found in the mapping file [file:/Users/ljnelson/Projects/foo/target/classes/META-INF/my-eclipselink-orm.xml] and the second in the mapping file [file:/Users/ljnelson/Projects/foo/target/classes/META-INF/my-real-orm.xml]. Named XML elements must be unique across the persistence unit.
那么如何用 eclipselink-orm.xml
覆盖 仅 "real" orm.xml
的某些部分 ?
这种情况包含在示例 6-4 中: http://www.eclipse.org/eclipselink/documentation/2.6/jpa/extensions/schema.htm
因为 my-eclipselink-orm.xml 被显式列出,所以它被视为 JPA orm.xml 文件。您需要将文件重命名为 eclipselink-orm.xml 并从 persistence.xml 中删除标记,以便您的情况与示例 6-3 匹配。文档声明它应该合并映射,但示例在这一点上并不清楚。