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

kma*_*oor 58 java jpa persistence.xml jpa-2.1

在网上快速搜索显示3或4个变体人们如何指定xmlnsxsi:schemaLocation进入persistence.xml.

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

我正在使用:

<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">
Run Code Online (Sandbox Code Playgroud)

And*_*i I 103

根据官方文件,它必须(和你的一样):

<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>
Run Code Online (Sandbox Code Playgroud)

  • +1.@kmansoor另外,为了指出显示此配置的确切位置,可以看到相关的XSD文件(从第50行开始):http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1. XSD (4认同)