Search code examples
javaeclipsejpaderby

Persistence unit error: javax.persistence.PersistenceException: No Persistence provider for EntityManager named


I have made a project in OSX in Java with Netbeans and working on it with colleagues that work on windows with github.

Once they clone the project they get below error that signifies that it cannot connect to the derby Database with eclipse.

Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named MovieDatabasePU
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
    at moviedatabase.MovieDatabase.deleteFromDB(MovieDatabase.java:126)
    at moviedatabase.MovieDatabase.main(MovieDatabase.java:48)
C:\Users\Mixalis\Documents\NetBeansProjects\Homework3\Ergasia3\nbproject\build-impl.xml:1076: The following error occurred while executing this line:
C:\Users\Mixalis\Documents\NetBeansProjects\Homework3\Ergasia3\nbproject\build-impl.xml:830: Java returned: 1
BUILD FAILED (total time: 2 seconds)

I have checked all the similar problems that are described on Stack, but the persistence.xml is correct and it is located on the META-INF folder which is located on the src/META-INF folder.

Below is the persistence file structure.

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
  <persistence-unit name="MovieDatabasePU" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>moviedatabase.entities.FavoriteList</class>
    <class>moviedatabase.entities.Genre</class>
    <class>moviedatabase.entities.Movie</class>
    <properties>
      <property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/person"/>
      <property name="javax.persistence.jdbc.user" value="pli24"/>
      <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
      <property name="javax.persistence.jdbc.password" value="pli24"/>
    </properties>
  </persistence-unit>
</persistence>

enter image description here

From the debugging the error occur on below statement:

 private static void deleteFromDB() {
        EntityManager em;
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("MovieDatabasePU"); <-- This line

        em = emf.createEntityManager();
        em.getTransaction().begin();

What could else be wrong, because I have tried almost every solution and still no database connection.


Solution

  • Well I only had to do a clean and Build to make it work!!! All files were ok and clean only wasn't enough.