views:

1168

answers:

2

I am writing an Eclipse plug-in that loads resources from a central database. I would like to use Hibernate to access that database.

So how would I add this as a dependency to my plug-in project? I've tried Google but only get hits on about plug-ins for editing Hibernate configuration files.

A: 

You could stick to the standard hibernate tutorials like the documentation provided at hibernate.org or Gaven Kings book, for using hibernate in combination within an eclipse rcp project.

The simplest way would be to include your Hibernate related code and your config in the plugin you currently develop.

Therefore your plugin has to depend on the jar files, each hibernate projects depends on. You could also provide these libs by a separated plugin and simply export them.

But you have to keep in mind that hibernate makes heavy use of reflection and your persistable classes have to be accessible for your persistence manager.

There is also a very good tutorial for integrating hibernate as a separate plugin on http://entwickler.de/zonen/portale/psecom,id,101,online,1082,.html but unfortunately it is only in german.

+1  A: 

I would create a hibernate plugin, that exposes all the hibernate jar files and exports the classes contained. My configuration and data would then be in another plugin that depends on hibernate.

Then, because hibernate uses reflection like no tomorrow, the Hibernate plug-in needs to be able to load classes from the plug ins that depend on it. To do that you need to use the Eclipse-BuddyPolicy directive. Check this documentation on classloading on eclipse that mentions BuddyPolicy

I've set up a Kodo JDO plug-in using this technique and it works quite well. A sample from my Manifest.mf is attached

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Solarmetric Kodo
Bundle-SymbolicName: com.solarmetric.kodo
Bundle-Activator: com.solarmetric.kodo.KodoPlugin
Bundle-Localization: plugin
Require-Bundle: org.eclipse.core.runtime
Eclipse-AutoStart: true
Eclipse-BuddyPolicy: global
Export-Package: com.solarmetric.ant,
 com.solarmetric.apache.commons.collections,
 com.solarmetric.apache.commons.collections.buffer,
 com.solarmetric.apache.commons.collections.collection,
 com.solarmetric.apache.commons.collections.functors,
 com.solarmetric.apache.commons.collections.iterators,
 com.solarmetric.apache.commons.collections.keyvalue,
Mario Ortegón