【问题标题】:javax.persistence.PersistenceException: No Persistence provider for EntityManager namedjavax.persistence.PersistenceException:没有名为 EntityManager 的持久性提供程序
【发布时间】:2015-11-08 16:35:12
【问题描述】:

您好,我是 Java Web 的新手,我遇到了一个问题,我得到了这个沟通 javax.persistence.PersistenceException:没有名为 NaszSerwisPU 的 EntityManager 的持久性提供程序

这是我的 persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence 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_1_0.xsd" version="1.0">
    <persistence-unit name="NaszSerwisPU" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <class>User</class>
    <properties>
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect"/>
        <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
        <property name="hibernate.show_sql" value="true"/>
        <property name="hibernate.connection.username" value="root"/>
        <property name="hibernate.connection.password" value="passsword"/>
        <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/naszserwis"/>
        <property name="hibernate.max_fetch_depth" value="3"/>
    </properties>
    </persistence-unit>
</persistence>

我试着打电话:

public String logIn() {
    EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("NaszSerwisPU");
    EntityManager mgr = entityManagerFactory.createEntityManager();

    User us = new User();
    us.setLogin("admin");
    us.setPassword("admin");

    mgr.persist(us);

    return "/main.xhtml";
}

我不知道我为什么会这样交流。 我使用 NetBeans

更新: 我已经删除了 hibernate.cfg.xml 并进行了更改

<provider>org.hibernate.ejb.HibernatePersistenceProvider></provider>  

到:

<provider>org.hibernate.jpa.HibernatePersistenceProvider></provider>

但问题依然存在,错误的沟通是一样的。

【问题讨论】:

    标签: java hibernate jpa


    【解决方案1】:

    如果使用 JPA 和 persistence.xml,则不需要 hibernate.cfg.xml

    我相信你应该写

    &lt;provider&gt;org.hibernate.jpa.HibernatePersistenceProvider&lt;/provider&gt;

    【讨论】:

      【解决方案2】:

      确保 persistence.xml 文件位于正确的位置。 看到这个Persistence.xml where to put in eclipse project

      【讨论】:

        猜你喜欢
        • 2011-04-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-14
        相关资源
        最近更新 更多