gpt4 book ai didi

java - 支持 JPA 的 OSGI bunfle 没有 Persistence provider 错误

转载 作者:行者123 更新时间:2023-11-29 05:47:45 24 4
gpt4 key购买 nike

我创建了支持 JPA2.0 的小型 OSGI buldle 项目来持久化 Student(实体类)对象。

我将能够成功启动此服务。

我已经创建了另一个客户端包项目来访问此服务。当我尝试启动客户端 buldle 服务时,出现以下错误

原因:javax.persistence.PersistenceException:没有名为 StudentJPAService 的 EntityManager 的持久性提供程序

请在下面找到完整的堆栈跟踪

!ENTRY StudentJPAClient 4 0 2013-03-04 14:17:21.846
!MESSAGE FrameworkEvent ERROR
!STACK 0
org.osgi.framework.BundleException: Exception in student.jpaclient.Activator.start() of bundle StudentJPAClient.
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:734)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)
at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:390)
at org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1176)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:559)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:544)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:457)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:243)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:438)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:1)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)
Caused by: java.lang.ExceptionInInitializerError
at com.student.jpaservice.serviceimpl.StudentDAOService.persist(StudentDAOService.java:16)
at student.jpaclient.Activator.start(Activator.java:30)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:711)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:702)
... 12 more
Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named StudentJPAService
at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
at com.student.jpaservice.util.StudentUtil.<clinit>(StudentUtil.java:11)
... 17 more
Root exception:
java.lang.ExceptionInInitializerError
at com.student.jpaservice.serviceimpl.StudentDAOService.persist(StudentDAOService.java:16)
at student.jpaclient.Activator.start(Activator.java:30)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:711)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:702)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)
at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:390)
at org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1176)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:559)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:544)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:457)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:243)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:438)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:1)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)
Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named StudentJPAService
at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
at com.student.jpaservice.util.StudentUtil.<clinit>(StudentUtil.java:11)
... 17 more

MANIFEST.MF

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: StudentJPAService
Bundle-SymbolicName: StudentJPAService;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: com.student.jpaservice.actovator.Activator
Import-Package: javax.persistence;version="1.1.0",
org.osgi.framework
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Export-Package: com.student.jpaservice.actovator,
com.student.jpaservice.model,
com.student.jpaservice.service,
com.student.jpaservice.serviceimpl,
com.student.jpaservice.util
Bundle-ActivationPolicy: lazy
Meta-Persistence: META-INF/persistence.xml
Bundle-ClassPath: ../lib/j2ee.jar,
../lib/javax.j2ee.persistence.jar,
../lib/mysql-connector-java-5.1.7-bin.jar,
.
JPA-PersistenceUnits: StudentJPAService

我在下面的帖子中看到了同样的问题,但它并没有帮助我解决我的问题。
OSGi + JPA(postgresql)

请帮我解决这个问题。

最佳答案

我意识到这无异于线程巫术,但我自己也曾为同样的问题苦苦挣扎了一段时间,直到我偶然发现了绕过持久性提供程序查找的解决方案。

使用这段代码...

EntityManagerFactory emf = new org.eclipse.persistence.jpa.PersistenceProvider().createEntityManagerFactory("unit_name_here", properties);
EntityManager manager = emf.createEntityManager();

...我直接调用 EclipseLink 并忽略整个服务提供商查找。我意识到这不是 super 可移植的,因为如果不重新编译模块就不能更换持久性提供程序,但我也不记得上次我想这样做是什么时候了。

希望这对将来的人有所帮助,并为他们节省我经历的一天半的头发拉扯时间!

关于java - 支持 JPA 的 OSGI bunfle 没有 Persistence provider 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15197859/

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