Eclipse and Hibernate and Class Loaders

I spent time today to have an Hibernate Hibernate Logo example running as Eclipse Plug-ins. Here is a trick to avoid NoClassDefFoundError when using Hibernate within Eclipse.

I have three Plug-ins :

  • com.mydomain.hibernate: Packaging of the hibernate Jar library in a Plug-in
  • com.mydomain.A
  • com.anotherdomain.B

These plugins have the following dependencies :

  • com.mydomain.hibernate depends on nothing (it’s a “library” Plug-in)
  • com.mydomain.A depends on B and on com.mydomain.hibernate
  • com.anotherdomain.B depends on nothing

The NoClassDefFoundError(org.hibernate.proxy.HibernateProxy) was fired when trying to map (in a database using hibernate of course) a class of com.anotherdomain.B in com.mydomain.A code.

The Eclipse ClassLoader mechanisms and the injection of new code from Hibernate in the com.anotherdomain.B are responsible for this error .

Here is THE article that helped me to understand what was happening here and to solve my problem using Eclipse-BuddyPolicy.


2 thoughts on “Eclipse and Hibernate and Class Loaders

  1. The problem with Eclipse-BuddyPolicy is that it doesn’t scale. As long as you have a few domain plug in that’s fine, but when the numbers are starting to get higher, you really don’t want to have to load all you domain plug in to start using your application.

    Another way to solve this problem, even if it is a bit more involved is to use Spring dynamic module (aka spring OSGI) which allows to wire the plugins at runtime, only when you need them.

  2. Hi Manuel,

    We’ve been working on packaging EclipseLink (JPA, JAXB, SDO) as OSGi bundles and in our Proof of Concept we were able to avoid the use of Equinox Buddy ClassLoading Policy. If you’re looking for high performance persistence you should check out EclipseLink ( and our OSGi proof of concept (

    EclipseLink will be available as OSGi bundles in the 1.0 release.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s