java 如何在 JPA 2.1 中指定实体映射?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17105445/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to specify entity mappings in JPA 2.1?
提问by Hajo Lemcke
A correct starting tag for the entity mappings file for JPA 2.0 was
JPA 2.0 实体映射文件的正确起始标记是
<entity-mappings version="1.0" 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">
What are the required corrections for JPA 2.1?
JPA 2.1 需要哪些更正?
I tried
我试过
<entity-mappings version="2.1" xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/orm">
But this gives the error:
但这给出了错误:
No grammar constraints (DTD or XML Schema) referenced in the document.
文档中没有引用语法约束(DTD 或 XML 架构)。
采纳答案by DataNucleus
As per what the JPA 2.1 spec says perhaps ;-) or the docs of a JPA 2.1 implementation that tells you
根据 JPA 2.1 规范可能所说的 ;-) 或告诉您的 JPA 2.1 实现的文档
Change java.sun.com to xmlns.jcp.org
将 java.sun.com 更改为xmlns.jcp.org
Change orm_1_0 to orm_2_1
将orm_1_0更改为orm_2_1
Change version="1.0" to version="2.1"
将 version="1.0" 更改为version="2.1"
回答by malloc4k
According to official documentation, section 12.3 XML Schema:
根据官方文档,第12.3节XML 架构:
<entity-mappings xmlns="http://xmlns.jcp.org/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence/orm
http://xmlns.jcp.org/xml/ns/persistence/orm_2_1.xsd"
version="2.1">
...
</entity-mappings>
回答by Hajo Lemcke
For version 2.1 the following is working:
对于 2.1 版,以下工作正常:
<?xml version="1.0" encoding="UTF-8" ?>
<persistence version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">