OSGi and JPA

Tutorial: Using JPA in an OSGi Environment - Part 2


JPA client bundle description


A client bundle represents a simple console application that uses EntityManager to manipulate with the JPA entities that are provided by the model bundle. The application is integrated into OSGi frameworks console commands with universal shell adapters.


A list of available commands (they all are listed with console “help” command):


• lsstuds – print student records

• lsgrps – print group records

• delgrp <id> – delete group record by ID

• delstud <id> – delete student record by ID

• addgrp <name> – add group record

• addstud <first_name> <last_name> <group_id> – add student record


JPA Service Specification (OSGi Enterprise Specification) describes that EntityManagerFactory service should be registered for every pair: Persistence Unit and Persistence Provider. In the client bundle on every command call we use EntityManagerFactory service instance that is available in OSGi registry (Client code sample – Listing 4).

The client bundle OSGi configuration is represented below (maven-bundle-plugin configuration – Listing 5). The most important OSGi MANIFEST headers are as follows:


• Import-Package should contain javax.persistence;version="1.1.0";jpa="2.0" to import JPA packages with required JPA version


• Import-Package should contain model package: org.knowhowlab.tips.jpa.mode



Gemini with EclipseLink configuration


The Gemini JPA project depicts modular implementations of Java Persistence API technology. This project currently provides the integration with the EclipseLink JPA provider to support the OSGi JPA specification approach that clients can use to get JPA support in an OSGi framework. The latest released version 1.0RC1 (25 March 2011) requires JDBC Service Specification (implemented by Gemini DBAccess) to access database and supports only Equinox as OSGi framework. In Listing 6, you can find a list of configuration bundles:




Aries with OpenJPA configuration


The Aries project delivers a set of pluggable Java components enabling an enterprise OSGi application programming model. This includes implementations and extensions of application-focused specifications defined by the OSGi Alliance Enterprise Expert Group.


Apache OpenJPA is a Java persistence project at The Apache Software Foundation that can be used as a stand-alone POJO persistence layer or integrated into any Java EE compliant container and many other lightweight frameworks. Listing 7 shows a list of configuration bundles. All tests of this configuration are passed except Knopflerfish OSGi framework test. It failed with some class loading exception.





Dmytro  Pishchukhin
Dmytro Pishchukhin

What do you think?

JAX Magazine - 2014 - 06 Exclucively for iPad users JAX Magazine on Android


Latest opinions