diff --git a/hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiSessionFactoryService.java b/hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiSessionFactoryService.java index 0dfeceb771..cba56af3ef 100644 --- a/hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiSessionFactoryService.java +++ b/hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiSessionFactoryService.java @@ -6,8 +6,6 @@ */ package org.hibernate.osgi; -import java.util.Collection; - import org.hibernate.SessionFactory; import org.hibernate.boot.MetadataBuilder; import org.hibernate.boot.MetadataSources; @@ -20,14 +18,15 @@ import org.hibernate.boot.registry.selector.StrategyRegistrationProvider; import org.hibernate.cfg.AvailableSettings; import org.hibernate.integrator.spi.Integrator; import org.hibernate.internal.CoreMessageLogger; - import org.jboss.logging.Logger; - import org.osgi.framework.Bundle; +import org.osgi.framework.FrameworkUtil; import org.osgi.framework.ServiceFactory; import org.osgi.framework.ServiceRegistration; import org.osgi.framework.wiring.BundleWiring; +import java.util.Collection; + /** * Hibernate 4.2 and 4.3 still heavily rely on TCCL for ClassLoading. Although * our ClassLoaderService removed some of the reliance, access to the proper ClassLoader @@ -67,8 +66,14 @@ public class OsgiSessionFactoryService implements ServiceFactory { @Override public Object getService(Bundle requestingBundle, ServiceRegistration registration) { final OsgiClassLoader osgiClassLoader = new OsgiClassLoader(); + + // First, add the client bundle that's requesting the OSGi services. osgiClassLoader.addBundle( requestingBundle ); + // Then, automatically add hibernate-core. These are needed to load resources + // contained in the core jar. + osgiClassLoader.addBundle( FrameworkUtil.getBundle(SessionFactory.class) ); + // Some "boot time" code does still rely on TCCL. "run time" code should all be using // ClassLoaderService now.