简体   繁体   中英

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

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

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>

I try to call:

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";
}

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

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

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

to:

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

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

You do not need hibernate.cfg.xml if you use JPA and persistence.xml

I believe you should write

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM