Hibernate in RCP

It’s good programming praxis to separate persistency from application logic from presentation logic. In my application I use EMF to create the data model and Teneo to link the model to either Hibernate or JDO. The EMF model, Teneo, database libraries, Hibernate and the libs required by Hibernate should all get their own OSGi-bundle / Eclipse-plugin. This helps to track and control dependencies between these pieces of separately developed software.

First of all install the plugins for EMF, Teneo and Derby from the Ganymede update¬† site (or library plugins for any other database supported by Hibernate). A Hibernate plugin is available too. But even if I tried everything a whole saturday afternoon long, I always run on this error: org.hibernate.MappingException: Could not determine type for: org.eclipse.emf.teneo.hibernate.mapping.econtainer.EContainerUserType I know this is related to the „Buddy nightmare“, and I followed the hints in the net, that suggest to use the Buddy-Registry in the plugins using hibernate. Nothing helped. So I decided to to create the required plugins myself. This gives me more control on the usage of libraries (logging) anyway.

So these are the plugins I created:

  1. antlr:  wraps the antlr.jar from the hibernate distribution. The manifest.mf must have the line: Eclipse-BuddyPolicy: dependent
  2. commons-collections: wraps the commons-collections.jar from the hibernate distro.
  3. dom4j: again a wrapper around the respective jar in the hibernate distro
  4. jta: the same
  5. sl4j: this time I took sl4j-api.jar and sl4j-jcl from the sl4j-package.The manifest declares a dependency to the commons-loggin plugin (available on the Ganymede update site, if not already installed): Require-Bundle: org.apache.commons.logging
  6. hibernate: contains only the hibernate3.jar. In the manifest the dependency to the 5 before mentioned plugins must be declared. And in addition Buddy-classloaders from dependent plugins must get access to the hibernate classes by Eclipse-BuddyPolicy: dependent

This does the job. My own code I keep in separate plugins for the EMF model classes (actually I preferred to use a simple OSGI bundle for this) and a second one with the application code. The application plugin must refer to emf.ecore, emf.teneo.hibernate, derby.core, the model bundle and our hibernate bundle as defined above. That’s it! In the application instances of the EMF model classes are created, modified and used in queries, and finally stored in a database. Cool stuff!

Leave a Reply

You must be logged in to post a comment.