OpenJPA 2.1.1 - Cannot find the declaration of element 'persistence'

若如初见. 提交于 2020-01-14 10:32:39

问题


I just downloaded http://www.apache.org/dyn/closer.cgi/openejb/4.0.0-beta-1/apache-tomee-1.0.0-beta-1-webprofile.zip to use OpenEJB with OpenJPA2.1.1. I can't get my persistence.xml working.

The top of the stack trace:

org.xml.sax.SAXException: file:/D:/Workspaces/sandbox/tomcat_ejb_jpa2_tomEE/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/testEE/WEB-INF/classes/META-INF/persistence.xml [Location: Line: 2, C: 248]: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'persistence'.

My persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" 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">
        <persistence-unit name="testEE">
        </persistence-unit>
</persistence>

I've read, that the problem should be solved with the namespace declaration (xmlns="http://java.sun.com/xml/ns/persistence"), but it still doesn't work.


回答1:


<?xml version="1.0"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
    version="2.0">
    <persistence-unit name="jpa-lib">
        <provider>org.apache.openjpa.persistence.PersistenceProviderImpl
        </provider>
        <class>com.dav.jpa.entity.Employee</class>
        <class>com.dav.jpa.entity.Department</class>
        <properties>
            <property name="openjpa.ConnectionURL" value="jdbc:oracle:thin:@localhost:1521:DVD" />
            <property name="openjpa.ConnectionDriverName" value="oracle.jdbc.OracleDriver" />
            <property name="openjpa.ConnectionUserName" value="scott" />
            <property name="openjpa.ConnectionPassword" value="tiger" />
            <property name="openjpa.Log" value="DefaultLevel=WARN, Tool=INFO" />
        </properties>
    </persistence-unit>
</persistence>

This is working for me..




回答2:


Does the problem disappear if you simplify your tag a bit?

<?xml version="1.0"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
  ...
</persistence>

I just encountered the same problem and fixed it using above BUT preceding this I just had

<persistence version="2.0">

as indicated in the OpenJpa manual.



来源:https://stackoverflow.com/questions/8311963/openjpa-2-1-1-cannot-find-the-declaration-of-element-persistence

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!