It would be great if the packaging of Hibernate could be done as osgi compatible jar. With little configuration, some plugins already exist to do it in simply.
For informaiton, a jar can become osgi-compatible only by adding some properties inside the META-INF/MANIFEST.MF file. It lets the jar totally usable in a non-osgi environment, but let the jar be recognized as a "bundle" in an osgi-container (Eclipse, Apache Felix...).
A good entrypoint for this, using maven2 to package, could be http://felix.apache.org/site/maven-bundle-plugin-bnd.html#MavenBundlePlugin(BND)-AddingOSGimetadatatoexistingprojectswithoutchangingthepackagingtype.
For example, Spring already did and their available jars on repo1.maven.org can be put directly in a eclipse/plugins directory and be recognized as a bundle/plugin.
Well, I'm no OSGi expert. But from my understanding, yes, dependencies also have to be present and osgi-compatible. But that's like project management, it's not your role to provide those jars osgi-ly. For example, in our company we have repackaged jars to be able to use them inside the "plugins" directory of Eclipse.
With OSGI, in the MANIFEST, basically you have to provide a "Bundle-symbolicName" (org.hibernate.hibernate-core for example), Export-Package and Import-Package (a Require-Bundle keyword also exist, but it's just a less-granular way of declaring dependencies against packages: see http://osdir.com/ml/ide.eclipse.equinox.devel/2006-03/msg00097.html for more information).
Happily enough, a tool has been developed to be able automatically generate those informations: BND, cf. http://www.aqute.biz/Code/Bnd. Btw, one of the samples using BND has been done with hibernate: http://www.aqute.biz/Code/BndHibernate.
And last but not least, maven-bundle-plugin is actually a maven plugin that uses BND library.
Some minutes ago, I quicky tested it and was able to generate a seemingly osgi compatible hibernate-core-3.3.SNAPSHOT jar (I'm going to attach the patch). To see if a jar is visible in an osgi container, I usually open Eclipse, drop the jar in plugins directory, window/preferences/Target platform. Then hit reload. For the current example, if you see org.hibernate.hibernate-core appear, then it's OK.
For more information, see also: http://blog.springsource.com/main/2008/02/18/creating-osgi-bundles/
Small patch on the hibernate-core pom.xml to use maven-bundle-plugin to package hibernate-core so that it's osgi-compatible.
Yes, I know all this but did you actually try and run this inside eclipse ?
Just because we stick some declarations into hibernate.jar does not make it actually work inside eclipse.
How did you test this ? Did you osgify all the other dependencies ?
Did classloading of user classes work correctly for you ?
Isn't Hibernate 4 planning to support OSGi anyway (see http://community.jboss.org/wiki/HibernateCoreMigrationGuide40)? Meanwhile, you could either use SpringSource's (outdated) version of Hibernate, or switch to EclipseLink.
Discussion moved to