OpenJPA 2.1.1 - Cannot find declaration of 'persistence' element

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 cannot get my persistence.xml to work.

Top of 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/MET INF / persistence.xml [Location: Line: 2, C: 248]: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the persistence declaration of the element.

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 read that the problem should be solved with the namespace declaration ( xmlns="http://java.sun.com/xml/ns/persistence" ), but it still does not work.

+4
source share
2 answers
 <?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 works for me ..

+2
source

Will the problem go away 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 ran into the same problem and fixed it using the above, but before that I just had

 <persistence version="2.0"> 

as indicated in the OpenJpa manual.

0
source

Source: https://habr.com/ru/post/1383650/


All Articles