Persistence.xml未正确配置

时间:2012-06-18 14:04:13

标签: java jdbc persistence ejb jta

我无法让这个持久性文件正确...我在书中找不到任何我用作指南的信息。我正在使用MySQL数据库。

<?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="a11_DA_g5_PU" transaction-type="JTA">
        <jta-data-source>a11_DA_g5</jta-data-source>
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <class>entities.Book</class>
        <class>entities.Author</class>
        <class>entities.Customer</class>
        <class>entities.Membership</class>
        <properties>
          <property name="eclipselink.target-database" value="DERBY"/>
          <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
          <property name="javax.persistence.jdbc.url" value="jdbc:mysql://studev.groept.be:3306/a11_DA_g5"/>
          <property name="javax.persistence.jdbc.user" value="a11_DA_g5"/>
          <property name="javax.persistence.jdbc.password" value="passwordhere"/>
          <property name="eclipselink.ddl-generation" value="create-tables"/>
        </properties>
      </persistence-unit>
    </persistence>

修改

严重:DPL8015:存档[EJBModule_jar]中的部署描述符文件META-INF / persistence.xml中的无效部署描述符。 第6行第15列 - cvc-complex-type.2.4.a:从元素'provider'开始发现无效内容。其中一个'{“http://java.sun.com/xml/ns/persistence":shared-cache-mode,,http://java.sun.com/xml/ns/persistence":validation-mode,预计会出现“http://java.sun.com/xml/ns/persistence":properties}”。

严重:DPL8005:部署描述符解析失败:cvc-complex-type.2.4.a:从元素'provider'开始发现无效内容。其中一个'{“http://java.sun.com/xml/ns/persistence":shared-cache-mode,,http://java.sun.com/xml/ns/persistence":validation-mode,预计会出现“http://java.sun.com/xml/ns/persistence":properties}”。

严重:部署应用[VaadinTestApp]

时出现异常

SEVERE:org.xml.sax.SAXParseException:cvc-complex-type.2.4.a:从元素'provider'开始发现无效内容。其中一个'{“http://java.sun.com/xml/ns/persistence":shared-cache-mode,,http://java.sun.com/xml/ns/persistence":validation-mode,预计“http://java.sun.com/xml/ns/persistence":properties}”。 java.io.IOException:org.xml.sax.SAXParseException:cvc-complex-type.2.4.a:从元素'provider'开始发现无效内容。其中一个'{“http://java.sun.com/xml/ns/persistence":shared-cache-mode,,http://java.sun.com/xml/ns/persistence":validation-mode,预计会出现“http://java.sun.com/xml/ns/persistence":properties}”。

2 个答案:

答案 0 :(得分:42)

<persistence-unit>内的元素顺序很重要,<jta-data-source>应该追溯<provider>

<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> 
<jta-data-source>a11_DA_g5</jta-data-source>         

答案 1 :(得分:8)

正如the XSD所述,<provider>元素必须位于<jta-data-source>元素之前。