OSGi and JPA
Tutorial: Using JPA in an OSGi Environment - Part 3
Aries with Hibernate configuration
Hibernate is an Object/Relational Mapping solution for Java environments. Hibernate EntityManager project implements the programming interfaces and lifecycle rules as defined by the JPA 2.0 specification.
In accordance with the fact that the Hibernate community does not supply Hibernate engine with OSGi bundle MANIFEST, we have to create it ourselves with maven-bundleplugin using a simpler version of configuration described by Peter Kriens (Listing 8).
The other point that we have to achieve is an activation of Hibernate Persistence Provider that will be available for Aries (Listing 9). Listing 10 shows a list of configuration bundles.
Aries with EclipseLink configuration
The Eclipse Persistence Services Project (EclipseLink) delivers a comprehensive open-source Java persistence solution. The EclipseLink JPA provides developers with a standards based Object-Relational persistence solution with additional support for many advanced features.
Though EclipseLink project delivers OSGi bundles, we have to activate EclipseLink Persistence Provider to make it available for Apache Aries (Listing 11). Listing 12 shows a list of configuration bundles.
It is possible to use EclipseLink as a standalone OSGi JPA provider. This solution has been announced as deprecated since version 2.2.0 but it can be used as well, if you do not feel like adding any extra libraries to support JPA. One extra header has been added to the model bundle to make Persistence Units available for the following EclipseLink configuration: JPA-PersistenceUnits: jpa.students. You can see a list of configuration bundles in Listing 13.
Run configurations and tests result
One of the main goals of the tutorial is to prove, that there is a feasible and easy way to run the same JPA model and client bundles with various configurations.
In this tutorial five different JPA configurations were created and every configuration was tested with three OSGi frameworks. The configurations can be run with:
mvn -f pom_<configuration>.xml -P <osgi_framework>
Available OSGi frameworks:
The test results are depicted in Table 1.
Summing up everything above, I would like to emphasize that the presented tutorial is only a starting point to use JPA in your OSGi environment. Consequently, we can speak about plenty of things that can be added and tested with the provided configurations: JPA provider features (e.g. cache, external transactions etc.), OSGi Enterprise features (e.g. Blueprint, Data Source Factories, JNDI etc.) and support of different databases.