Skip to content

vogellacompany/EclipseLink-and-Hibernate-JPA-OSGi

 
 

Repository files navigation

Hibernate and EclipseLink in an OSGi Runtime and Eclipse 4

This repo shows how to use JPA in an OSGi environment and with Eclipse 4.

It provides products for both EclipseLink and Hibernate.

Building and running the projects

cd com.vogella.jpa
./mvnw clean verify

After the successful build you can navigate to either the /home/simon/git/com.vogella.jpa/com.vogella.jpa.product.eclipselink/target/products/vogella-jpa-eclipselink/your OS/your ws/your arch/vogella-jpa-eclipselink or /com.vogella.jpa/com.vogella.jpa.product.hibernate/target/products/vogella-jpa-hibernate/your OS/your ws/your arch/vogella-jpa-hibernate and run the vogella-jpa-eclipselink or vogella-jpa-hibernate runnable.

Architecture

The com.vogella.jpa.e4.client bundle, which contains the Eclipse 4 application and implicitly uses EclipseLink or Hibernate is completely decoupled from the underlying ORM mapper.

jpa osgi architecture

I do not want to compare these two JPA implementations, but just mention that it is easier to include EclipseLink into a project, which uses an OSGi runtime, e.g., Eclipse, because for Hibernate it was still necessary to add the Eclipse-BuddyPolicy: registered instruction in the models MANIFEST.MF file and to register the com.vogella.jpa.service.eclipselink project as buddy (Eclipse-RegisterBuddy: com.vogella.jpa.model).

Another point is that EclipseLink provides their OSGi bundles in a p2 update site (http://download.eclipse.org/rt/eclipselink/updates/) and Hibernate had to be added to the dependencies project, which generates a p2 update site. See dependencies for further information.

Development

Building the project with Maven Tycho is nice, but as a developer you might want to see the code und run it from the Eclipse IDE. Therefore just clone and import the project, set the target platform, which is specified in the com.vogella.jpa.target project, and run the com.vogella.jpa.eclipselink.product product or the com.vogella.jpa.hibernate.product product.

The Projects

dependencies

The dependencies projects uses bnd-platform in order to generate a p2 update site for the H2 database and the Hibernate hibernate dependencies. See build.gradle and bnd-platforms documentation to see how this is done.

But no worries the p2 update site, which is generated is already available here: https://dl.bintray.com/simon-scholz/H2-Database-Engine/ and also being used in the target platform definition file.

com.vogella.jpa.target

This project consists of a com.vogella.jpa.target.target target definition file, which should be set as target platform for the workspace so that all projects compile.

com.vogella.jpa.model

This is a simple data model for the clients containing a Todo entity and an TodoService interface, but completely decoupled from EclipseLink or Hibernate. So it is pretty much like a DAO or a Spring data repository.

Implement the TodoService interface and registers this implementation as an OSGi service so that it can the obtained by clients.

Depending on which product is started com.vogella.jpa.service.eclipselink or com.vogella.jpa.service.hibernate will be part of the product and therefore provide the actual implementation of the TodoService.

com.vogella.jpa.e4.client

This client is an Eclipse 4 RCP application, which only has a dependency to the com.vogella.jpa.model package and simply injects the TodoService into a sample part in order to show Todo objects in a sample part.

Please feel free to add new features like deleting or adding Todo objects, since the TodoService service already offers these methods as well.

Other projects

The other projects are just containing the features and products for either EclipseLink or Hibernate.

Contributing

Feedback is highly appreciated and pull requests are appreciated even more.

So please feel free to ask for enhancements or offer pull requests for missing features.

About

Hibernate and EclipseLink in an OSGi Runtime and Eclipse 4

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%