javax.persistence.PersistenceException:没有名为EntityManager的持久性提供程序 [英] javax.persistence.PersistenceException: No Persistence provider for EntityManager named

查看:68
本文介绍了javax.persistence.PersistenceException:没有名为EntityManager的持久性提供程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我是Java Web的新手,我有一个问题,需要进行交流 javax.persistence.PersistenceException:名为NaszSerwisPU的EntityManager的持久性提供程序

Hello I am new in Java Web and I have a problem that I get this communicate javax.persistence.PersistenceException: No Persistence provider for EntityManager named NaszSerwisPU

这是我的persistence.xml

Here is my 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

I don`t know why i get this communicate. I use NetBeans

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

UPDATE: I had removed hibernate.cfg.xml and changed

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

收件人:

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

但是问题仍然存在,错误的传达是相同的.

but problem still exist, communicate of error is the same.

推荐答案

确保persistence.xml文件在正确的位置. 参见将Persistence.xml放入Eclipse项目的位置

Make sure that persistence.xml file is in the right location. See this Persistence.xml where to put in eclipse project

这篇关于javax.persistence.PersistenceException:没有名为EntityManager的持久性提供程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆