dana-i2cat/opennaas — pull request #52 by gbehrmann (2012-03-16 08:53:38+00:00)
Title: Feature/use openjpa

Hibernate is known to be difficult to use in an OSGi context, partly
because it isn't packaged as a bundle and thus requires repackaging.

This patch replaces Hibernate with OpenJPA in OpenNaaS. OpenJPA is
available as a bundle and thus doesn't require repackaging.

Several OpenNaaS classes made explicit use of the Hibernate API. This
patch changes those classes to use the JPA API when possible. In one
case the OpenJPA API needs to be used directly: OpenNaaS's DAO
interface makes use of query by example and this functionality is not
available in JPA 2.

Access to the JDBC driver is always challenging in an OSGi context.
Previously we added a dynamic-import to our repackaged Hibernate
bundle. This allowed it to load the JDBC driver. The Aries JPA
recommended approach is however to configure the persistence.xml file
to lookup a data source through JNDI. Using this mechanism, the JDBC
driver is loaded by our opennaas-core-resources bundle, which publishes
the data source as an OSGi service. Thus no dynamic import is required.
This also has the benefit that it becomes easier to inject
configuration values when setting up the data source (should we wish to
do so in the future).