![](/img/trans.png)
[英]javax.persistence.PersistenceException: No Persistence provider for EntityManager named aramis
[英]javax.persistence.PersistenceException: No Persistence provider for EntityManager named
您好,我是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>
但是问题仍然存在,错误的传达是相同的。
如果您使用JPA和persistence.xml,则不需要hibernate.cfg.xml
我相信你应该写
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
确保persistence.xml文件在正确的位置。 看到这个Persistence.xml放在Eclipse项目的位置
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.