1

i know that this question have been asked a thousand times but i couldn't find a solution that work for me so i'm asking it again. I'm trying to make a simple project with only one class and hibernate . But i've got this error when i try access to my webpage :

javax.persistence.PersistenceException: No Persistence provider for EntityManager named testhibernate0
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:61)
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
servlet.Main.start(Main.java:21)
servlet.Servlet.doGet(Servlet.java:14)
javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

Here is my class Personne.java :

package bean;
import java.util.ArrayList;

import javax.persistence.*;

@Entity
@Table( name = "personne")
public class Personne {

    @Id 
    @GeneratedValue
    private int id ;

    private String nom ;

    @ManyToOne
    @JoinColumn(name="Maison")
    private ArrayList<Maison> listMaison;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getNom() {
        return nom;
    }

    public void setNom(String nom) {
        this.nom = nom;
    }

    public ArrayList<Maison> getListMaison() {
        return listMaison;
    }

    public void setListMaison(ArrayList<Maison> listMaison) {
        this.listMaison = listMaison;
    }

    public void addMaison(Maison maison) {
        listMaison.add(maison);
    }

}

And here is my file persistence.xml (i've found on google that i should have one for properties and to get rid of that stupid error but it didn't worked)

<?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="testhibernate0" transaction-type="RESOURCE_LOCAL">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <class>Personne</class>
        <properties>
              [...]
        </properties>
    </persistence-unit>
</persistence>

And here is a screenshot of my jars : clic here

If someone could help me ...

Thx

Raedwald
  • 46,613
  • 43
  • 151
  • 237
Antoine Grenard
  • 1,712
  • 3
  • 21
  • 41

1 Answers1

0

I want to give you 2 suggestions.

At first, make sure that the persistence.xml file is in the following directory:

/WEB-INF/classes/META-INF

Secondly, change the provider <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> instead of <provider>org.hibernate.ejb.HibernatePersistence</provider>

UPDATE1:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>4.2.6.Final</version>
</dependency>

Use this dependency in your pom.xml with previous provider <provider>org.hibernate.ejb.HibernatePersistence</provider>

Resource Link:

  1. No Persistence provider for EntityManager named
  2. No Persistence provider for EntityManager named X
  3. javax.persistence.PersistenceException: No Persistence provider for EntityManager named customerManager
Community
  • 1
  • 1
SkyWalker
  • 28,384
  • 14
  • 74
  • 132
  • So i've tried as you sais to put the it there : /WEB-INF/classes/META-INF/persistence.xml but it didn't worked. Same thing when i change the provider .. It didn't worked – Antoine Grenard Jun 20 '16 at 16:26
  • When i'm trying it with org.hibernate.ejb.HibernatePersistence i've got another error i don't know if it's better or not ... "Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set" – Antoine Grenard Jun 20 '16 at 16:35
  • @Antoine Please have a try with UPDATE1 portion – SkyWalker Jun 20 '16 at 16:40
  • I've resolved my problem ! thx for the help man you gave me some ideas – Antoine Grenard Jun 21 '16 at 08:01