持久性.xml未正确配置

2022-09-02 05:16:05

我无法正确获取此持久性文件...我在书中找不到任何更多的信息作为指导。我正在使用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: 部署描述符文件 META-INF/持久性.xml存档 [EJBModule_jar] 中的部署描述符无效。第 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“:p roperties}” 之一是预期的。

严重: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“:p roperties}” 之一是预期的。

严重:部署应用程序时出现异常 [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“:p roperties}” 之一是预期的。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“:p roperties}” 之一是预期的。


答案 1

里面元素的顺序很重要,应该去之后:<persistence-unit><jta-data-source><provider>

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

答案 2

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


推荐