2015-08-15 73 views
0

你好,我在的Java Web是新的,我有我得到这个沟通 javax.persistence.PersistenceException一个问题:没有找到EntityManager的持久性提供者名为NaszSerwisPUjavax.persistence.PersistenceException:否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> 

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

回答

0

如果使用JPA你不需要的hibernate.cfg.xml和persistence.xml中

我相信你应该写

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

相关问题