![](/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.