javax.persistence.PersistenceException: No Persistence provider for EntityManager named in Karaf 4.0.7 and OSGi DS test

#1

Hello,

I've written a small OSGi Declarative Services application to run in Apache Karaf 4.0.7 to persist an entity into an ObjectDB database.

I'm working in C/S model and I have both the ObjectDB server and Karaf running on localhost.

When I try to persist the entity I'm getting the 

javax.persistence.PersistenceException: No Persistence provider for EntityManager named objectdb://localhost:6136/technolink.odb;user=admin;password=admin

exception in the Karaf log.

I have deployed the objectdb.jar file that I fixed in order to make it a valid OSGi bundle.

I have attached:

1) my bundle to deploy to Karaf

2) the objectdb bundle I use

3) a zip file containing the source project (Eclipse Neon.1, Bndtools 3.3.0).

In order to build the code, you need to have lombok in the classpath (https://projectlombok.org) and lombok enabled in Eclipse (https://projectlombok.org/download.html).

I saw a thread in the forum (form 2011 - http://www.objectdb.com/database/forum/286) that refers to the same exception and the workaround is to change the classloader. I suppose in that case, the objectdb.jar file was included in the bundle that is supposed to reference it.

I want to deploy objectdb.jar file only once to my karaf and use it like any other OSGi bundle.

Many thanks in advance for your precious feedback,

Alex

 

#2

BTW: I forgot to mention that if I set the classloader in the @Activate method:

oldClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(EntityManagerFactory.class.getClassLoader());

then it works.

Regards,

Alex

#3

This error message is produced by JPA if it cannot find an appropriate JPA implementation in the classpath. You must make sure that ObjectDB is available in the context class loader. Setting the context class loader, as suggested in #2 above, is a known solution.

ObjectDB Support
#4

Hello,

thank you for confirming that changing the class path is the right way to go. At least I'm not missing something really obvious then.

Are you planning to improve OSGi support in order to support e.g. Declarative Services and possibly provide EntityManagerFactory as a service such that one simply needs to request a reference to the service?

Would be nice if one could simply drop the objectdb bundle into the runtime, request a reference to the Factory and not having to worry about where it is coming from.

Regards,

Alex

#5

This is possible, but we prefer to avoid introducing our own API, so possibly this can be achieved if a future version of JPA will define a standard API for OSGi integration.

 

ObjectDB Support
#6

Hello,

OK, sounds like a plan.

Regards,

Alex

Reply