21

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.

mmvie
  • 2,571
  • 7
  • 24
  • 39
  • And what does the error message say? Error messages are intended to be read. I'm sure it doesn't just say "Something's wrong". – JB Nizet Jun 18 '12 at 14:09

2 Answers2

51

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>         
axtavt
  • 239,438
  • 41
  • 511
  • 482
  • Ok, that seems to improve things. Getting another error now: Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'values IDENTITY_VAL_LOCAL()' at line 1 – mmvie Jun 18 '12 at 14:45
  • Note that `eclipselink.target-database` is `DERBY`, but connection URL points to MySQL. – axtavt Jun 18 '12 at 14:49
  • Finding that strange as well, but I cannot find anything how to point it to MySQL. Can you show me the way? – mmvie Jun 18 '12 at 15:00
  • @mmvie Change the value for that property to mysql – Mark Rotteveel Jun 18 '12 at 15:13
  • Okay, it works BUT I need to create the tables inside the database myself. My handbook is telling me it should create the tables itself once it creates the entities, do I need to enable that or is there some kind of setting/property in the xml? – mmvie Jun 18 '12 at 15:16
  • http://stackoverflow.com/questions/4612187/eclipselink-does-not-generate-tables-from-annotated-jpa-classes does it! Thanks all! – mmvie Jun 18 '12 at 15:21
  • 2
    Wow. The _order_ of the elements matters? I know that isn't really XML's fault at all, but still...one more reason to dislike XML. Annotations, anyone? – aroth Jan 15 '14 at 14:22
  • @aroth annotations can get just as ugly. Order may not matter as much but still... – cbmeeks Jul 03 '14 at 23:04
10

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

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • What determinate if elements should be in order or not is: `xsd:sequence` (determinate order) `xsd:all` (no order) – FiruzzZ Sep 22 '17 at 11:49