【问题标题】:Could not find any META-INF/persistence.xml file in the classpath Java - Dynamic Web Project在类路径 Java 中找不到任何 META-INF/persistence.xml 文件 - 动态 Web 项目
【发布时间】:2019-12-05 14:39:30
【问题描述】:

我的问题与Could not find any META-INF/persistence.xml file in the classpath 相同,我需要帮助了解如何将我的 persistence.xml 文件简单地添加到类路径中。

App.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);
    }
}

persistence.xml

<?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 中,为什么会显示错误。

【问题讨论】:

    标签: java xml jpa


    【解决方案1】:

    对我有帮助

    我从 File-> New -> JPA Project 创建了一个新的 JPA 项目。

    它为我提供了正确的 META-INF 位置 文件夹,其中包含

    persistence.xml

    然后我将 JPA 项目方面添加到我的项目中,并提供与我的数据库连接相关的所有必要细节。

    只需运行我的 App.java 文件。

    它运行。

    新项目来源

    【讨论】:

      猜你喜欢
      • 2018-01-17
      • 1970-01-01
      • 2014-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-21
      • 2014-09-22
      相关资源
      最近更新 更多