Java 如何在persistence.xml 中指定JPA 2.1?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21142168/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 06:52:37  来源:igfitidea点击:

How to specify JPA 2.1 in persistence.xml?

javajpajpa-2.1persistence.xml

提问by kmansoor

A quick search on the Net reveals three or four variants how folks have been specifying xmlnsand xsi:schemaLocationin persistence.xml.

在网络上快速搜索会发现三四个变体,人们是如何指定xmlnsxsi:schemaLocationpersistence.xml.

What would be the 'correct' manner to specify JPA version 2.1?

指定 JPA 2.1 版的“正确”方式是什么?

I'm using

我正在使用

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

采纳答案by Andrei I

According to the official documentationit must be (like yours):

根据官方文档,它必须是(像你的一样):

<persistence 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"
             version="2.1">
    ...
</persistence>