Using Hibernate in an Eclipse RCP Application

I recently worked on a project in which a server side application was implemented as an Eclipse RCP Application. Leveraging the eclipse plugin framework, we organized our components into eclipse plugins. This application connects to a number of datasources so we decided to use hibernate as our OR mapping layer. We created a Hibernate Plugin that wraps the hibernate framework (hibernate3.jar). Other plugins that requires database access would have to “require” the hibernate plugin declared in their plugin.xml. These client plugins to hibernate will then define/contain their own hibernate config and mapping files. This all makes a lot of sense until we started up the application and discover that Hibernate is not able to locate the mapping files. Doh!

One way to solve this problem is to use Buddy Classloading Strategy in the OSGi layer. In a nutshell, Buddy Classloading is like this…

The hibernate plugin can register itself to be a “Buddy” by declaring “Eclipse-BuddyPolicy: registered” in its OSGi manifest. This is basically saying “Hey, I am a nice plugin and I want to be somebody’s buddy”. Other plugins that is interested in using hibernate can declare “Eclipse-RegisterBuddy: hibernate” in their OSGi manifest. This allows hibernate plugin to load classes that is in its buddy plugins.

Note that, other frameworks (e.g. Spring) that uses ContextClassloader to load domain specifc resources suffers the same kind of symptoms as Hibernate does.

Happy buddy-classloading…

It's only fair to share...
Share on Facebook
Tweet about this on Twitter
Share on LinkedIn

Leave a Reply