![](/img/trans.png)
[英]Could not find any META-INF/persistence.xml file in the classpath
[英]Could not find any META-INF/persistence.xml file in the classpath Java - Dynamic Web Project
我的问题与此相同无法在类路径中找到任何 META-INF/persistence.xml 文件,我需要帮助了解如何将我的 persistence.xml 文件添加到类路径中。
应用程序.java
package JPA;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
public class App {
public static void main (String args[]) {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("pu");
EntityManager em = emf.createEntityManager();
Alien a = em.find(Alien.class,2);
}
}
持久化文件
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0" >
<persistence-unit name="pu">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/akash"/>
<property name="javax.persistence.jdbc.user" value="root"/>
</properties>
</persistence-unit>
</persistence>
在这里,我对持久性有点困惑” version="1.0" 是否正确?
> 错误
在类路径中找不到任何 META-INF/persistence.xml 文件
没有名为 pu 的 EntityManager 的持久性提供程序
我的 persistence.xml 文件存储在 META-INF 中,所以为什么它显示 error 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.