1
votes

I want to create the OSGI persistence service bundle with JPA 2.0. I am using OpenJpa as a persistence provider.

I tried a sample OSGI bundle with JPA support and I faced the problem when my client call the persistence functionality. The service couldnt create the EntityManagerFactory. Always it is null.

I am using Apache Karaf as the platform to install the services.

Currently I am creating a OSGI bundle in eclipse and export it as a bundle and deploy it in Karaf. The client can call the service. But the issue is when I get EntityManagerFactory.

I am using bellow code to get EntityManagerFactory.

  OpenJPAEntityManagerFactory emf = OpenJPAPersistence.createEntityManagerFactory
    ("StudentServiceProvider","META-INF/persistence.xml");

Please provide me a clear idea how can I create the OSGI persitence bundle with OpenJPA.

2

2 Answers

1
votes
5
votes

If you're using Karaf you're better off using the Aries jpa feature for Karaf, which provides a nice JPA integration in an OSGi environment. It avoids many classloading issues and allows you to take advantage of other container services like transaction management, if you want them. You can still use OpenJPA as your JPA provider. See for example this tutorial on JaxEnter, or these slides which explain why JPA on its own has issues.