带有TopLink的JPA:在类路径中找不到META-INF / persistence.xml [英] JPA with TopLink: No META-INF/persistence.xml was found in classpath

查看:142
本文介绍了带有TopLink的JPA:在类路径中找不到META-INF / persistence.xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public class LoginTest {

public static void main(String[] args) {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("IRCBotPU");
    EntityManager em = emf.createEntityManager();

    em.getTransaction().begin();

    Login lg = new Login();
    lg.setPassword("password");
    lg.setUserName("Rocky");

    em.persist(lg);
    em.flush();

    Login st = em.find(Login.class, lg.getPassword());
    System.out.println(st);

    em.getTransaction().commit();

    em.close();
    emf.close();

}
}

我收到异常时我尝试运行这个类

I'm getting an Exception when I try to run this class

javax.persistence.PersistenceException: No Persistence provider for EntityManager named IRCBotPU:  
   No META-INF/persistence.xml was found in classpath.

META-INF / persistence.xml在我的类路径中。我不知道是什么原因或这个例外。

META-INF/persistence.xml is in my classpath. I don't know what is the reason or this exception.

持久性库是TopLink。

Persistence library is TopLink.

推荐答案

我有同样的问题,我把我的persistence.xml文件保存在WebContent / META-INF目录中,而jpa规范说:

根目录持久性单元是WEB-INF / classes目录;因此,persistence.xml文件包含在WEB-INF / classes / META-INF目录中


尝试将persistence.xml放在src / META-INF下。

I had the same problem, i was keeping my persistence.xml file in the WebContent/META-INF directory, while the jpa specification says:
the root of the persistence unit is the WEB-INF/classes directory; the persistence.xml file is therefore contained in the WEB-INF/classes/META-INF directory
try placing persistence.xml under src/META-INF.

这篇关于带有TopLink的JPA:在类路径中找不到META-INF / persistence.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆