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

This commit is contained in:
Brett Meyer 2015-08-24 23:23:03 -04:00
parent 45cea33fbe
commit 9870b5967f
1 changed files with 10 additions and 0 deletions

View File

@ -6,7 +6,10 @@
*/ */
package org.hibernate.osgi; package org.hibernate.osgi;
import org.hibernate.SessionFactory;
import org.hibernate.jpa.HibernateEntityManagerFactory;
import org.osgi.framework.Bundle; import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceFactory; import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceRegistration; import org.osgi.framework.ServiceRegistration;
@ -36,8 +39,15 @@ public class OsgiPersistenceProviderService implements ServiceFactory {
@Override @Override
public Object getService(Bundle requestingBundle, ServiceRegistration registration) { public Object getService(Bundle requestingBundle, ServiceRegistration registration) {
final OsgiClassLoader osgiClassLoader = new OsgiClassLoader(); final OsgiClassLoader osgiClassLoader = new OsgiClassLoader();
// First, add the client bundle that's requesting the OSGi services.
osgiClassLoader.addBundle( requestingBundle ); osgiClassLoader.addBundle( requestingBundle );
// Then, automatically add hibernate-core and hibernate-entitymanager. These are needed to load resources
// contained in those jars, such as em's persistence.xml schemas.
osgiClassLoader.addBundle( FrameworkUtil.getBundle( SessionFactory.class ) );
osgiClassLoader.addBundle( FrameworkUtil.getBundle( HibernateEntityManagerFactory.class ) );
// Some "boot time" code does still rely on TCCL. "run time" code should all be using // Some "boot time" code does still rely on TCCL. "run time" code should all be using
// ClassLoaderService now. // ClassLoaderService now.