From 9870b5967fb76f056d084723b4b2a198b06d0b87 Mon Sep 17 00:00:00 2001 From: Brett Meyer Date: Mon, 24 Aug 2015 23:23:03 -0400 Subject: [PATCH] HHH-10044 automatically add hibernate-core and hibernate-entitymanager Bundles to OsgiClassLoader --- .../hibernate/osgi/OsgiPersistenceProviderService.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiPersistenceProviderService.java b/hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiPersistenceProviderService.java index 04c4911a5a..8f76c405a1 100644 --- a/hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiPersistenceProviderService.java +++ b/hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiPersistenceProviderService.java @@ -6,7 +6,10 @@ */ package org.hibernate.osgi; +import org.hibernate.SessionFactory; +import org.hibernate.jpa.HibernateEntityManagerFactory; import org.osgi.framework.Bundle; +import org.osgi.framework.FrameworkUtil; import org.osgi.framework.ServiceFactory; import org.osgi.framework.ServiceRegistration; @@ -36,8 +39,15 @@ public class OsgiPersistenceProviderService 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 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 // ClassLoaderService now.