381 words

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

#1
2016-12-05 08:12

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

 

alexweirig
alexweirig's picture
Joined on 2016-11-30
User Post #3
#2
2016-12-05 10:29

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

alexweirig
alexweirig's picture
Joined on 2016-11-30
User Post #4
#3
2016-12-05 14:13

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
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #2,669
#4
2016-12-05 14:59

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

alexweirig
alexweirig's picture
Joined on 2016-11-30
User Post #7
#5
2016-12-07 08:35

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
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #2,671
#6
2016-12-08 07:47

Hello,

OK, sounds like a plan.

Regards,

Alex

alexweirig
alexweirig's picture
Joined on 2016-11-30
User Post #9

Post Reply

Please read carefully the posting instructions - before posting to the ObjectDB website.

  • You may have to disable pop up blocking in order to use the toolbar (e.g. in Chrome).
  • Use ctrl + right click to open the browser context menu in the editing area (e.g. for using a browser spell checker).
  • To insert formatted lines (e.g. Java code, stack trace) - select a style in the toolbar and then insert the text in the new created block.
  • Avoid overflow of published source code examples by breaking long lines.
  • You may mark in paragraph code words (e.g. class names) with the code style (can be applied by ctrl + D).
  • Long stack traces (> 50 lines) and complex source examples (> 100 lines) should be posted as attachments.
Attachments:
Maximum file size: 32 MB
Cancel