我知道这个问题已经被问了一千遍了,但是我找不到适合我的解决方案,所以我再问一次。
我正在尝试仅使用一个类并休眠一个简单的项目。但是当我尝试访问我的网页时遇到了这个错误:

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)


这是我的类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);
    }

}


这是我的文件persistence.xml(我在google上发现我应该为属性设置一个,并且摆脱了那个愚蠢的错误,但是没有用)

<?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>


这是我的罐子的屏幕截图:clic here

如果有人可以帮助我...

谢谢

最佳答案

我想给你2条建议。

首先,请确保persistence.xml文件位于以下目录中:

/WEB-INF/classes/META-INF

其次,更改提供者<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>而不是<provider>org.hibernate.ejb.HibernatePersistence</provider>

UPDATE1:

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


在您的pom.xml中与以前的提供者<provider>org.hibernate.ejb.HibernatePersistence</provider>一起使用此依赖项

资源链接:


No Persistence provider for EntityManager named
No Persistence provider for EntityManager named X
javax.persistence.PersistenceException: No Persistence provider for EntityManager named customerManager

关于java - 没有名为testhibernate0的EntityManager的持久性提供程序,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37926113/

10-12 00:37