org.xml.sax.SAXParseException;行号:10;列数:18; cvc-complex-type.2.4.a: 发现以元素 'properties' 开头的无效内容

org.xml.sax.SAXParseException; lineNumber: 10; columnNumber: 18; cvc-complex-type.2.4.a: Invalid content was found starting with element 'properties'

我按照教程做了 link here

我得到

Caused by: org.xml.sax.SAXParseException; lineNumber: 10; columnNumber: 18; cvc-complex-type.2.4.a: Invalid content was found starting with element 'properties'. One of '{"http://xmlns.jcp.org/xml/ns/persistence":property}' is expected.

指向我的 presistence.xml,如下所示:

<?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">
 <persistence-unit name="loginTestPU" transaction-type="RESOURCE_LOCAL">
  <class>entities.User</class>
  <properties>   
    <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/p?zeroDateTimeBehavior=convertToNull"/>
    <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
    <property name="javax.persistence.jdbc.user" value="User"/>
    <property name="javax.persistence.jdbc.password" value="p"/>
    <properties/>
    </persistence-unit>
    </persistence>

需要什么样的属性?

还在视频中使用了 Eclipse_JPA 库,我安装了 netbeans 8.1,它没有这个库,我使用 EclipseLink(JPA2.1) 代替。这只是我的实现与视频中的实现之间的区别。

</properties>代替<properties/>

<properties/> 只不过是 <properties/> <properties/> 的缩写,但是如果你想在 <properties/> <properties/> 之间添加你想要在你的情况下做的东西,你不能使用 <properties/>