Javax.persistence.PersistenceException:无效的persistence.xml

时间:2014-01-24 02:46:42

标签: xml hibernate jpa

我是JPA的新手,我在Netbeans中与JPA合作 我的persistence.xml文件有错误,但我不知道如何解决它:

错误消息:

35940 [main] INFO org.hibernate.ejb.Version - Hibernate EntityManager 3.6.6.Final
[2014-01-24 10:00:28,025] ERROR: Unable to prepare PXS
javax.persistence.PersistenceException: Invalid persistence.xml.
Error parsing XML (line-1 : column -1): cvc-elt.1: cannot find the declaration of element 'persistence'.
    at org.hibernate.ejb.packaging.PersistenceXmlLoader.loadURL(PersistenceXmlLoader.java:145)
    at org.hibernate.ejb.packaging.PersistenceXmlLoader.deploy(PersistenceXmlLoader.java:169)
    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:317)
    at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
    at org.astri.ims.ccs.tps.persistence.TPSPersister.<init>(TPSPersister.java:119)
    at org.astri.ims.ccs.tps.persistence.TPSPersister.getInstance(TPSPersister.java:127)
    at org.astri.ims.ccs.pxs.necontrol.nce.NeControlEngine.prepare(NeControlEngine.java:109)
    at org.astri.ims.ccs.pxs.PXSComponent.prepare(PXSComponent.java:273)
    at org.astri.ims.ccs.CCSMain.prepareComponents(CCSMain.java:202)
    at org.astri.ims.ccs.CCSMain.startServer(CCSMain.java:446)
    at org.astri.ims.ccs.CCSMain.main(CCSMain.java:571)
[2014-01-24 10:00:28,027] ERROR: Failed to prepare the component:Proxy Services

我已经厌倦了将版本从2.1改为2.0,here说 但是这对我不起作用。
这是我的persistence.xml文件:

的persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://java.sun.com/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="Ent_ccserverPU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>org.entitymodel.Clientassociation</class>
         a lots of entities here...
<class>org.entitymodel.Ipset</class>
<properties>
  <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/ims?zeroDateTimeBehavior=convertToNull"/>
  <property name="javax.persistence.jdbc.password" value="mypswd"/>
  <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
  <property name="javax.persistence.jdbc.user" value="root"/>
</properties>
  </persistence-unit>
</persistence>

我尝试将persistence.xml更改为:(如here所述。)

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" 
         version="2.0">
  <persistence-unit name="Ent_ccserverPU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>org.entitymodel.Clientassociation</class>
  Some entities here...
<class>org.entitymodel.Ipset</class>
<properties>
  <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/ims?zeroDateTimeBehavior=convertToNull"/>
  <property name="javax.persistence.jdbc.password" value="mypswd"/>
  <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
  <property name="javax.persistence.jdbc.user" value="root"/>
</properties>
  </persistence-unit>
</persistence>

但徒劳无功。

我的persistence.xml是由Netbeans生成的,我尝试在另一个项目中构建这个文件,它工作正常,所以我不知道是什么问题。

请帮帮我。 提前谢谢!

1 个答案:

答案 0 :(得分:0)

您遗漏了持久性XML文件的结束标记。

添加

</persistence-unit>
</persistence>

到文件的末尾,你应该好好去!