Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jpa 如何用eclipselink-orm.xml文件覆盖而不是替换orm.xml文件中的某些元素?_Jpa_Eclipselink - Fatal编程技术网

Jpa 如何用eclipselink-orm.xml文件覆盖而不是替换orm.xml文件中的某些元素?

Jpa 如何用eclipselink-orm.xml文件覆盖而不是替换orm.xml文件中的某些元素?,jpa,eclipselink,Jpa,Eclipselink,报告部分说: 此映射文件可用于替代JPA的标准映射文件,或者可用于覆盖JPA映射文件 我对做后者感兴趣,而不是前者 因此,我将以下内容放入我的META-INF/persistence.xml文件中: <mapping-file>META-INF/my-orm.xml</mapping-file> <mapping-file>META-INF/my-eclipselink-orm.xml</mapping-file> …然后EclipseLink对

报告部分说:

此映射文件可用于替代JPA的标准映射文件,或者可用于覆盖JPA映射文件

我对做后者感兴趣,而不是前者

因此,我将以下内容放入我的
META-INF/persistence.xml
文件中:

<mapping-file>META-INF/my-orm.xml</mapping-file>
<mapping-file>META-INF/my-eclipselink-orm.xml</mapping-file>
…然后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.
发现具有相同名称[名称]的冲突XML元素[]。第一个在映射文件[file:/Users/ljnelson/Projects/foo/target/classes/META-INF/my eclipselink orm.xml]中找到,第二个在映射文件[file:/Users/ljnelson/Projects/foo/target/classes/META-INF/my real orm.xml]中找到。命名的XML元素在整个持久性单元中必须是唯一的。
那么,如何使用
eclipselink orm.xml
覆盖“real”orm.xml的某些部分?

以下示例6-4介绍了这种情况:


因为my-eclipselink-orm.xml是显式列出的,所以它被视为JPA orm.xml文件。您需要将该文件重命名为eclipselink-orm.xml,并从persistence.xml中删除该标记,以便您的情况与示例6-3相匹配。文档中说明它应该合并映射,但示例在这一点上并不清楚

谢谢你,克里斯;因此,为了清楚起见,该文件必须有一个神奇的名称
META-INF/eclipselink orm.xml
——也就是说,将其命名为其他名称总是会导致异常?这是我从引用的URL中得到的一个外卖。如果有关系的话,在我的例子中,正如我在问题中提到的,我没有
META-INF/orm.xml
,只有其他任意命名的对象关系映射文件。所以在
target/classes
中,我有
META-INF/my real orm.xml
和(现在)META-INF/eclipselink orm.xml。当然,我的
persistence.xml
与我的主要资源的打包无关,它位于
测试类/META-INF
中。EclipseLink在
测试类/META-INF
中搜索
EclipseLink orm.xml
,当然没有找到它。我原以为它是在类路径上查找的,而不是以某种方式“锚定”到
persistence.xml
?绑定到持久性单元的文件总是相对于persistence.xml。我从文档中了解到,META-INF/eclipselink-orm.xml相对于persistence.xml是eclipselink orm文件的默认位置,因此,如果它位于persistence.xml中,则不需要将其包含在persistence.xml中。否则,如果它在persistence.xml文件中被命名,它将被用作orm.xml,不允许重叠。如果我有一个专门提到
META-INF/orm.xml
testclasses/META-INF/persistence.xml
,并且该文件位于
classes
(不是
testclasses
)中,那么一切正常。所以我很好奇为什么
eclipselink orm.xml
在这种行为上是独一无二的。persistence.xml中明确列出的任何内容都是从类路径中提取的。默认情况下,任何留待查找的内容,例如entities或orm.xml,都是相对于持久性单元的。
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.