异常 javax.persistence.PersistenceException:没有 EntityManager 的持久性提供程序

发布于 2024-10-01 21:21:36 字数 1682 浏览 4 评论 0 原文

我们已经为此努力了好几天,但我们被难住了。这应该是一个使用 TopLink 的简单教程。在我们开发真正的网络应用程序之前,我们正试图让它发挥作用。这是我们得到的以下异常:

线程“main”中出现异常 javax.persistence.PersistenceException:名为 pu1 的 EntityManager 没有持久性提供程序:
以下提供商:
oracle.toplink.essentials.PersistenceProvider
oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider
返回 null 给 createEntityManagerFactory。
在 javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:154)
在 javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
在 client.Client.main(Client.java:45)
Java 结果:1

从我们的 emf 驱动程序类执行此行后会发生这种情况:

emf = Persistence.createEntityManagerFactory("pu1");

我假设问题出在我们的 persistence.xml 文件中(位于正确的文件夹 (WEB-INF/classes/META-INF) 中。还有 netbeans为我们生成了 xml 文件,内容是:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" 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">
<persistence-unit name="JPAExamplePU" transaction-type="JTA">
<provider>oracle.toplink.essentials.PersistenceProvider</provider>
<jta-data-source>SomeDB</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="toplink.ddl-generation" value="drop-and-create-tables"/>
</properties>
</persistence-unit>
</persistence>

我们还认为这可能是添加库问题或类似的问题,非常感谢您的帮助。

We've been working on this for days and we are stumped. This is supposed to be an easy tutortial using TopLink. We are trying to get this to work before we do our real web app. This is the following exception we get:

Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named pu1:
The following providers:
oracle.toplink.essentials.PersistenceProvider
oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider
Returned null to createEntityManagerFactory.
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:154)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
at client.Client.main(Client.java:45)
Java Result: 1

this happens after executing this line from our emf driver class:

emf = Persistence.createEntityManagerFactory("pu1");

I'm assuming the problem is in our persistence.xml file (which is in the correct folder (WEB-INF/classes/META-INF). Also netbeans generated the xml file for us which is:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" 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">
<persistence-unit name="JPAExamplePU" transaction-type="JTA">
<provider>oracle.toplink.essentials.PersistenceProvider</provider>
<jta-data-source>SomeDB</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="toplink.ddl-generation" value="drop-and-create-tables"/>
</properties>
</persistence-unit>
</persistence>

We were also thinking it may be an adding a library issue or something along that line. Any help is much appreciated. Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

滴情不沾 2024-10-08 21:21:36

您的持久性单元名称错误。使用 xml 中的一个(即用 定义的一个):

emf = Persistence.createEntityManagerFactory("JPAExamplePU");

You have the wrong persistence unit name. Use the one from the xml (i.e. the one defined with <persistence-unit name="..."):

emf = Persistence.createEntityManagerFactory("JPAExamplePU");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文