没有持久性提供程序错误的OSGI bunfle与JPA支持

时间:2013-03-04 09:03:06

标签: java osgi osgi-bundle

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

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

我创建了另一个客户端捆绑项目来访问此服务。当我尝试启动客户端缓牌服务时,我收到了以下错误

引起: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)

请帮我解决此问题。

3 个答案:

答案 0 :(得分:1)

我建议将Aries JPA与OpenJPA或Eclipselink一起用作持久性提供程序。我建议OpenJPA,因为Eclipselink支持仍然非常新鲜。

有关完整示例,您可以看到我的Apache Karaf DB tutorial。它包含一个jpa示例。

答案 1 :(得分:1)

我意识到这等于线程死灵,但我一直在努力解决同样的问题,直到我偶然发现绕过持久性提供程序查找批发的解决方案。

使用此代码......

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

...我直接调用EclipseLink并忽略整个服务提供者查找。我意识到,在没有重新编译模块的情况下你可以换掉持久性提供程序,这并不是超级便携的,但我也记不起上次我想要这样做了。

希望这可以帮助将来的某个人并为他们节省一天半的头发拉动我已经完成了!

答案 2 :(得分:0)

似乎在你的bundle中,你还没有定义任何持久性管理器,比如Hibernate,Eclipse Link,等等......

检查你的依赖树,在你的导入包中你只定义了两个包,osgi核心和JPA,但JPA只是一个规范(接口),你需要一个实现这些接口的引擎。