HHH-10044 automatically add hibernate-core and hibernate-entitymanager Bundles to OsgiClassLoader

This commit is contained in:
Brett Meyer 2015-08-26 15:10:33 -04:00
parent 9626603e75
commit 66b90e3b2d
1 changed files with 9 additions and 4 deletions

View File

@ -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.