我刚刚下载了http://www.apache.org/dyn/closer.cgi/openejb/4.0.0-beta-1/apache-tomee-1.0.0-beta-1-webprofile.zip以将OpenEJB与OpenJPA2.1.1一起使用。 我无法使我的persistence.xml工作。
堆栈顶部的跟踪:
org.xml.sax.SAXException: 文件:/ 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: 找不到元素'持久性'的声明。
我的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>
我已经读过,问题应该通过名称空间声明(xmlns="http://java.sun.com/xml/ns/persistence"
)来解决,但它仍然不起作用。
答案 0 :(得分:2)
<?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>
这对我有用..
答案 1 :(得分:0)
如果稍微简化标记,问题是否会消失?
<?xml version="1.0"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
...
</persistence>
我刚刚遇到同样的问题并使用上面的 BUT 修复了它我刚才有了
<persistence version="2.0">
如OpenJpa手册中所示。