0
votes

My problem s just same as this Could not find any META-INF/persistence.xml file in the classpath and i need to help about how i just simply add my persistence.xml file into the in the classpath.

App.java

package JPA;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class App {
    public static void main (String args[]) {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("pu");
        EntityManager em = emf.createEntityManager();
        Alien a = em.find(Alien.class,2);
    }
}

persistence.xml

<?xml version="1.0" encoding="UTF-8"?>

<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0"  >   
    <persistence-unit name="pu">   
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <properties>
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/akash"/>
            <property name="javax.persistence.jdbc.user" value="root"/>

        </properties>
    </persistence-unit>
</persistence>

Here i am little confused about the persistence" version="1.0" is correct or not ?

> Error

Could not find any META-INF/persistence.xml file in the classpath

No Persistence provider for EntityManager named pu

enter image description here

my persistence.xml file is stored into the META-INF so why it shows error .

1

1 Answers

0
votes

It helps me

I created a new JPA Project from File-> New -> JPA Project.

It provided me the correct location of META-INF Folder which is consists of

persistence.xml

Then i add the JPA Project Facets to my project and provided all the necessary details related to my database connection.

Simply run my App.java file .

It runs.

New Project Source

enter image description here