HHH-8553 hibernate-osgi needs to support alternative locations for
hibernate.cfg.xml
This commit is contained in:
parent
55d941944d
commit
9e5ba931fb
|
@ -46,17 +46,16 @@
|
|||
|
||||
<!-- These do not natively support OSGi, so using 3rd party bundles. -->
|
||||
<bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.antlr/2.7.7_5</bundle>
|
||||
<bundle>mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.jsr303-api-1.0.0/2.2.0</bundle>
|
||||
<bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.ant/1.8.2_2</bundle>
|
||||
<bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.dom4j/1.6.1_5</bundle>
|
||||
|
||||
<!-- These do not natively support OSGi, so wrap with BND. -->
|
||||
<bundle>wrap:mvn:org.jboss/jandex/1.1.0.Alpha1</bundle>
|
||||
|
||||
<bundle>wrap:mvn:org.hibernate.common/hibernate-commons-annotations/4.0.2.Final</bundle>
|
||||
<bundle>mvn:com.fasterxml/classmate/0.5.4</bundle>
|
||||
<bundle>mvn:com.fasterxml/classmate/0.8.0</bundle>
|
||||
<bundle>mvn:org.jboss.logging/jboss-logging/3.1.0.GA</bundle>
|
||||
<bundle>mvn:org.javassist/javassist/3.18.0-GA</bundle>
|
||||
<bundle>mvn:org.javassist/javassist/3.18.1-GA</bundle>
|
||||
|
||||
<bundle>mvn:org.hibernate.common/hibernate-commons-annotations/4.0.3.Final</bundle>
|
||||
|
||||
<bundle>mvn:org.hibernate/hibernate-core/4.3.0-SNAPSHOT</bundle>
|
||||
<bundle>mvn:org.hibernate/hibernate-entitymanager/4.3.0-SNAPSHOT</bundle>
|
||||
|
|
|
@ -21,17 +21,16 @@
|
|||
|
||||
<!-- These do not natively support OSGi, so using 3rd party bundles. -->
|
||||
<bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.antlr/2.7.7_5</bundle>
|
||||
<bundle>mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.jsr303-api-1.0.0/2.2.0</bundle>
|
||||
<bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.ant/1.8.2_2</bundle>
|
||||
<bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.dom4j/1.6.1_5</bundle>
|
||||
|
||||
<!-- These do not natively support OSGi, so wrap with BND. -->
|
||||
<bundle>wrap:mvn:org.hibernate.common/hibernate-commons-annotations/4.0.2.Final</bundle>
|
||||
<bundle>wrap:mvn:org.jboss/jandex/1.1.0.Alpha1</bundle>
|
||||
|
||||
<bundle>mvn:com.fasterxml/classmate/0.5.4</bundle>
|
||||
<bundle>mvn:com.fasterxml/classmate/0.8.0</bundle>
|
||||
<bundle>mvn:org.jboss.logging/jboss-logging/3.1.0.GA</bundle>
|
||||
<bundle>mvn:org.javassist/javassist/3.18.0-GA</bundle>
|
||||
<bundle>mvn:org.javassist/javassist/3.18.1-GA</bundle>
|
||||
|
||||
<bundle>mvn:org.hibernate.common/hibernate-commons-annotations/4.0.3.Final</bundle>
|
||||
|
||||
<bundle>mvn:org.hibernate/hibernate-core/4.3.0-SNAPSHOT</bundle>
|
||||
<bundle>mvn:org.hibernate/hibernate-entitymanager/4.3.0-SNAPSHOT</bundle>
|
||||
|
|
|
@ -21,12 +21,9 @@
|
|||
|
||||
<!-- These do not natively support OSGi, so using 3rd party bundles. -->
|
||||
<bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.antlr/2.7.7_5</bundle>
|
||||
<bundle>mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.jsr303-api-1.0.0/2.2.0</bundle>
|
||||
<bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.ant/1.8.2_2</bundle>
|
||||
<bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.dom4j/1.6.1_5</bundle>
|
||||
|
||||
<!-- These do not natively support OSGi, so wrap with BND. -->
|
||||
<bundle>wrap:mvn:org.hibernate.common/hibernate-commons-annotations/4.0.2.Final</bundle>
|
||||
<bundle>wrap:mvn:org.jboss/jandex/1.1.0.Alpha1</bundle>
|
||||
<!-- Optional. Needed to test C3P0 connection pools. -->
|
||||
<!-- <bundle>wrap:mvn:c3p0/c3p0/0.9.1</bundle> -->
|
||||
|
@ -35,9 +32,11 @@
|
|||
<!-- Optional. Needed to test ehcache 2lc. -->
|
||||
<!-- <bundle>wrap:mvn:net.sf.ehcache/ehcache-core/2.4.3</bundle> -->
|
||||
|
||||
<bundle>mvn:com.fasterxml/classmate/0.5.4</bundle>
|
||||
<bundle>mvn:com.fasterxml/classmate/0.8.0</bundle>
|
||||
<bundle>mvn:org.jboss.logging/jboss-logging/3.1.0.GA</bundle>
|
||||
<bundle>mvn:org.javassist/javassist/3.18.0-GA</bundle>
|
||||
<bundle>mvn:org.javassist/javassist/3.18.1-GA</bundle>
|
||||
|
||||
<bundle>mvn:org.hibernate.common/hibernate-commons-annotations/4.0.3.Final</bundle>
|
||||
|
||||
<!-- JACC is optional. -->
|
||||
<!--<bundle>mvn:javax.servlet/javax.servlet-api/3.0.1</bundle>
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
*/
|
||||
package org.hibernate.osgi;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.SessionFactory;
|
||||
|
@ -29,12 +30,15 @@ import org.hibernate.boot.registry.selector.StrategyRegistrationProvider;
|
|||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.integrator.spi.Integrator;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.metamodel.spi.TypeContributor;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.jboss.logging.Logger;
|
||||
import org.osgi.framework.Bundle;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.ServiceFactory;
|
||||
import org.osgi.framework.ServiceRegistration;
|
||||
import org.osgi.framework.wiring.BundleWiring;
|
||||
|
||||
/**
|
||||
* Hibernate 4.2 and 4.3 still heavily rely on TCCL for ClassLoading. Although
|
||||
|
@ -55,6 +59,9 @@ import org.osgi.framework.ServiceRegistration;
|
|||
* @author Tim Ward
|
||||
*/
|
||||
public class OsgiSessionFactoryService implements ServiceFactory {
|
||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class,
|
||||
OsgiSessionFactoryService.class.getName());
|
||||
|
||||
private OsgiClassLoader osgiClassLoader;
|
||||
private OsgiJtaPlatform osgiJtaPlatform;
|
||||
private BundleContext context;
|
||||
|
@ -81,7 +88,21 @@ public class OsgiSessionFactoryService implements ServiceFactory {
|
|||
|
||||
final Configuration configuration = new Configuration();
|
||||
configuration.getProperties().put( AvailableSettings.JTA_PLATFORM, osgiJtaPlatform );
|
||||
|
||||
// Allow bundles to put the config file somewhere other than the root level.
|
||||
final BundleWiring bundleWiring = (BundleWiring) requestingBundle.adapt( BundleWiring.class );
|
||||
final Collection<String> cfgResources = bundleWiring.listResources( "/", "hibernate.cfg.xml",
|
||||
BundleWiring.LISTRESOURCES_RECURSE );
|
||||
if (cfgResources.size() == 0) {
|
||||
configuration.configure();
|
||||
}
|
||||
else {
|
||||
if (cfgResources.size() > 1) {
|
||||
LOG.warn( "Multiple hibernate.cfg.xml files found in the persistence bundle. Using the first one discovered." );
|
||||
}
|
||||
String cfgResource = "/" + cfgResources.iterator().next();
|
||||
configuration.configure( cfgResource );
|
||||
}
|
||||
|
||||
final BootstrapServiceRegistryBuilder builder = new BootstrapServiceRegistryBuilder();
|
||||
builder.with( osgiClassLoader );
|
||||
|
|
Loading…
Reference in New Issue