Results 1 to 3 of 3
  1. #1
    spac is offline Member
    Join Date
    Feb 2009
    Posts
    5
    Rep Power
    0

    Default No Persistence provider problem with Maven

    Hi,
    please help me with following JPA problem:

    I create an Entity class "Book.java" which maps database table "book".
    Then I create class "Main.java" which persist data to MySQL database.
    When I run Main class from Eclipse IDE (Run/Run as/Java application) it works fine and save data to database. But when I try to do this with maven, build fails:
    • mvn compile works fine and produce BUILD SUCCESS, but
    • mvn exec:java -Dexec.mainClass="com.apress.javaee6.chapter02.Main " produce following error:

    [ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2:java <default-cli> on project jpamaven: An exception occured while executing the Java class. null: InvocationTargetException: No Persistence provider for EntityManager named chapter02PU

    My persistence.xml file has this content:

    <?xml version="1.0" encoding="UTF-8"?>
    <persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.1">

    <persistence-unit name="chapter02PU" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceP rovider</provider>
    <class>com.apress.javaee6.chapter02.Book</class>
    <properties>
    <property name="eclipselink.target-database" value="MySQL"></property>
    <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"></property>
    <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/chapter02db" />
    <property name="javax.persistence.jdbc.user" value="root"></property>
    <property name="javax.persistence.jdbc.password" value="root"></property>
    <property name="eclipselink.ddl-generation" value="create-tables"></property>
    <property name="eclipselink.logging.level" value="INFO"></property>
    </properties>
    </persistence-unit>
    </persistence>




    I am new in Maven, but my opinion is that problem could be with some missing dependency in pom.xml file:

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.appres.javaee6</groupId>
    <artifactId>jpamaven</artifactId>
    <version>1.0</version>
    <name>jpamaven</name>

    <dependencies>
    <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.14</version>
    </dependency>

    <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.5</version>
    <scope>test</scope>
    </dependency>

    <dependency>
    <groupId>javax.persistence</groupId>
    <artifactId>persistence-api</artifactId>
    <version>1.0</version>
    <type>jar</type>
    <scope>compile</scope>
    </dependency>
    </dependencies>

    <build>
    <plugins>
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.2</version>
    </plugin>
    </plugins>
    </build>
    </project>



    Project structure:

    jpamaven
    -- src
    -- -- main
    -- -- -- java
    -- -- -- -- com
    -- -- -- -- -- apress
    -- -- -- -- -- -- javaee6
    -- -- -- -- -- -- -- chapter02
    -- -- -- -- -- -- -- -- Book.java
    -- -- -- -- -- -- -- -- Main.java
    -- -- -- resources
    -- -- -- -- META-INF
    -- -- -- -- -- persistence.xml
    -- -- test
    -- -- -- java
    -- -- -- resources
    -- target
    -- -- classes
    -- -- -- com
    -- -- -- -- apress
    -- -- -- -- -- javaee6
    -- -- -- -- -- -- chapter02
    -- -- -- -- -- -- -- Book.class
    -- -- -- -- -- -- -- Main.class
    -- -- -- META-INF
    -- -- -- -- persistence.xml





    Any ideas why maven canīt build this project?

    .

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,792
    Rep Power
    19

    Default

    <provider>org.eclipse.persistence.jpa.PersistenceP rovider</provider>

    That class (or at least the jar that class is in) does not seem to be in your list of dependencies. Looks like a default Eclipse one to me.

  3. #3
    spac is offline Member
    Join Date
    Feb 2009
    Posts
    5
    Rep Power
    0

    Default

    Quote Originally Posted by Tolls View Post
    <provider>org.eclipse.persistence.jpa.PersistenceP rovider</provider>

    That class (or at least the jar that class is in) does not seem to be in your list of dependencies. Looks like a default Eclipse one to me.

    Yes, you were right.
    Thanks for guide me where the problem is.

    I add following dependencies to my pom.xml:

    <dependency>
    <groupId>org.eclipse.persistence</groupId>
    <artifactId>javax.persistence</artifactId>
    <version>1.1.0</version>
    </dependency>
    <dependency>
    <groupId>org.eclipse.persistence</groupId>
    <artifactId>eclipselink</artifactId>
    <version>1.1.0</version>
    </dependency>


    I also have to add <repository> element:

    <repositories>
    <repository>
    <id>EclipseLink Repo</id>
    <url>http://www.eclipse.org/downloads/download.php?r=1&amp;nf=1&amp;file=/rt/eclipselink/maven.repo</url>
    <!-- use this for javax.persistence
    <snapshots>
    <enabled>true</enabled>
    </snapshots> -->
    </repository>
    </repositories>


    Now it works.

    Thanks :-)

Similar Threads

  1. problem with Persistence.createEntityManagerFactory
    By jordanthompson in forum Advanced Java
    Replies: 7
    Last Post: 12-24-2009, 12:38 PM
  2. Replies: 0
    Last Post: 07-09-2009, 11:11 AM
  3. Replies: 0
    Last Post: 04-20-2009, 06:26 PM
  4. Replies: 0
    Last Post: 03-08-2009, 01:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •