Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Persistence.xml not correctly configured

Tags:

I'm not able to get this persistence file correct... I do not find any more information in the book that I use as a guide. I'm using a MySQL database.

<?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>

EDIT

SEVERE: DPL8015: Invalid Deployment Descriptors in Deployment descriptor file META-INF/persistence.xml in archive [EJBModule_jar]. Line 6 Column 15 -- cvc-complex-type.2.4.a: Invalid content was found starting with element 'provider'. One of '{"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}' is expected.

SEVERE: DPL8005: Deployment Descriptor parsing failure : cvc-complex-type.2.4.a: Invalid content was found starting with element 'provider'. One of '{"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}' is expected.

SEVERE: Exception while deploying the app [VaadinTestApp]

SEVERE: org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'provider'. One of '{"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}' is expected. java.io.IOException: org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'provider'. One of '{"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}' is expected.

like image 938
mmvie Avatar asked Jun 18 '12 14:06

mmvie


People also ask

What is a persistence XML file?

The persistence. xml file is a standard configuration file in JPA. It has to be included in the META-INF directory inside the JAR file that contains the entity beans. The persistence. xml file must define a persistence-unit with a unique name in the current scoped classloader.

How do I edit persistence xml?

In the Package Explorer view, right-click the persistence. xml file of the JPA project that you want to edit and select Open with > Persistence XML Editor. In the Design tab of the Persistence XML Editor, make any of the following changes to the persistence.

Where is the persistence XML file?

If you package the persistence unit as a set of classes in a WAR file, persistence. xml should be located in the WAR file's WEB-INF/classes/META-INF directory.

Does spring boot need persistence xml?

Spring Boot will not search for or use a META-INF/persistence. xml by default. If you prefer to use a traditional persistence. xml , you need to define your own @Bean of type LocalEntityManagerFactoryBean (with an ID of 'entityManagerFactory') and set the persistence unit name there.


2 Answers

Order of elements inside <persistence-unit> is important, <jta-data-source> should go after <provider>:

<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> 
<jta-data-source>a11_DA_g5</jta-data-source>         
like image 61
axtavt Avatar answered Oct 16 '22 18:10

axtavt


As the XSD says, the <provider> element must come before the <jta-data-source> element.

like image 40
JB Nizet Avatar answered Oct 16 '22 18:10

JB Nizet