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

时间:2014-01-15 15:59:08

标签: java jpa jpa-2.1 persistence.xml

网上的快速搜索显示了3个或4个变体,人们如何在xmlns中指定xsi:schemaLocationpersistence.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">

1 个答案:

答案 0 :(得分:102)

根据official documentation它必须(和你的一样):

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