我正在做网络应用。我发现了很多同样问题的问题
但我没有得到正确答案。我的文件夹结构和类路径一切都是正确的,但为什么这个异常发生真的我不知道。
以下是我的文件夹结构。这里persistence.xml文件位于src文件夹的META-INF文件夹中
我的Persistance.xml:
<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="jspWithJpa" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.entity.Student</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/reports" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="root" />
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
</properties>
</persistence-unit>
</persistence>
EntityManagerUtil
public class EntityManagerUtil {
private static final EntityManagerFactory emf;
static {
try {
emf = Persistence.createEntityManagerFactory("jspWithJpa");
}
catch (Throwable ex) {
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static EntityManagerFactory getEmf() {
return emf;
}
}
异常是:
Initial SessionFactory creation failed.javax.persistence.PersistenceException: No Persistence provider for EntityManager named jspWithJpa
Mar 2, 2014 11:16:08 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [com.action.InsertData] in context with path [/jspWithJpa] threw exception [Servlet execution threw an exception] with root cause
javax.persistence.PersistenceException: No Persistence provider for EntityManager named jspWithJpa
答案 0 :(得分:1)
将您的提供商代码更改为persistence.xml
至:
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
从你的嘴唇,我可以看到你使用eclipselink作为JPA提供者,而不是休眠。