cayenne-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Cristiano Ghersi <>
Subject Re: Cayenne under OSGi
Date Mon, 25 Nov 2013 15:48:45 GMT
Hi Andrus, great job!

I have to say that we always used it under Equinox implementation, so
perhaps in Felix seems to be simpler.

Just two notes on our experience under OSGi that may help to overcome
eventual problems of class/resource loading.
1) OSGi load of resources like xml config file: this sometimes is tricky
under OSGi. We solved our problems creating another bundle as a fragment
host of cayenne-osgi bundle, where we place the **.map.xml, the
cayenne-MyDomain.xml and (optionally) the (as we use
org.apache.commons.dbcp for pooled connections).
2) Class loading: if your bundle expose some methods to interact with DB,
the lazy load of the classes inside OSGi environment may bring you some
headache, as you cannot be sure on the order of class loading among the
different bundles (this is why we provided the ClassRegistry and force the
load of such classes in the start() of the bundle: to be sure that such
classes are correctly loaded from the correct bundle when we want!). This
strange behavior was discovered after one year that we were using Cayenne
under OSGi! So, perhaps, the fact that now with the test bundle Andrus
provided everything seems working can be misleading. But I cannot prove my
sentence as this is a bug very difficult to reproduce.

So, at the end, the implementation of Andrus seems effective and works well
for me, but the test of someone else may give us more feeling about the
resolution of the issue.


2013/11/24 Andrus Adamchik <>

> So this is done. Cristiano, appreciate if you could try it in your
> environment. An example of how to use Cayenne with OSGi is available on
> GitHub [1]. Here is how you bootstrap it in your own module:
>   Module osgiModule =
> OsgiModuleBuilder.forProject(Activator.class).withDriver(Driver.class).module();
>   return new ServerRuntime("cayenne-osgi-example.xml", osgiModule);
> As you see, no need to enumerate your classes. Also I suspect instead of
> binding the driver, in a real OSGi environment Cayenne stack will need to
> refer to some OSGi service that encapsulates the DataSource. We can provide
> integrations for that too. And don’t forget to stop it when you your bundle
> is stopped, as you don’t want to keep Cayenne threads and other resources
> hanging around, eventually killing your container:
>   cayenneRuntime.shutdown();
> Cheers,
> Andrus
> [1]

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message