gpt4 book ai didi

java - 在类路径中找不到任何 META-INF/persistence.xml 文件 Java - Dynamic Web Project

转载 作者:行者123 更新时间:2023-12-01 19:37:45 25 4
gpt4 key购买 nike

我的问题和这个一样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"是否正确感到有点困惑?

>错误

Could not find any META-INF/persistence.xml file in the classpath

No Persistence provider for EntityManager named pu

enter image description here

我的 persistence.xml 文件存储在 META-INF 中,所以为什么它显示错误。

最佳答案

这对我有帮助

I created a new JPA Project from File-> New -> JPA Project.

It provided me the correct location of META-INF Folder which is consists of

persistence.xml

Then i add the JPA Project Facets to my project and provided all the necessary details related to my database connection.

Simply run my App.java file .

It runs.

新项目来源

enter image description here

关于java - 在类路径中找不到任何 META-INF/persistence.xml 文件 Java - Dynamic Web Project,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59197514/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com