Permalink
Browse files

HHH-8015 Spring 3.2.1 cannot be deployed on JBoss AS7 with Hibernate …

…4.1.6 due to class loader issues.
  • Loading branch information...
1 parent 52f2edf commit a6c46408df22c7d14475139e3e333126ac80e66d @stliu stliu committed Feb 18, 2013
@@ -495,6 +495,14 @@
public static final String NON_CONTEXTUAL_LOB_CREATION = "hibernate.jdbc.lob.non_contextual_creation";
/**
+ * Used to define a {@link java.util.Collection} of the {@link ClassLoader} instances Hibernate should use for
+ * class-loading and resource-lookups.
+ *
+ * @since 4.2
+ */
+ public static final String CLASSLOADERS = "hibernate.classLoaders";
+
+ /**
* Names the {@link ClassLoader} used to load user application classes.
* @since 4.0
*/
@@ -23,11 +23,14 @@
*/
package org.hibernate.service;
+import java.util.ArrayList;
import java.util.LinkedHashSet;
+import java.util.List;
import org.hibernate.integrator.internal.IntegratorServiceImpl;
import org.hibernate.integrator.spi.Integrator;
import org.hibernate.service.classloading.internal.ClassLoaderServiceImpl;
+import org.hibernate.service.classloading.spi.ClassLoaderService;
import org.hibernate.service.internal.BootstrapServiceRegistryImpl;
/**
@@ -40,10 +43,8 @@
*/
public class BootstrapServiceRegistryBuilder {
private final LinkedHashSet<Integrator> providedIntegrators = new LinkedHashSet<Integrator>();
- private ClassLoader applicationClassLoader;
- private ClassLoader resourcesClassLoader;
- private ClassLoader hibernateClassLoader;
- private ClassLoader environmentClassLoader;
+ private List<ClassLoader> providedClassLoaders;
+ private ClassLoaderService providedClassLoaderService;
/**
* Add an {@link Integrator} to be applied to the bootstrap registry.
@@ -61,47 +62,84 @@ public BootstrapServiceRegistryBuilder with(Integrator integrator) {
*
* @param classLoader The class loader to use
* @return {@code this}, for method chaining
+ *
+ * @deprecated Use {@link #with(ClassLoader)} instead
*/
@SuppressWarnings( {"UnusedDeclaration"})
+ @Deprecated
public BootstrapServiceRegistryBuilder withApplicationClassLoader(ClassLoader classLoader) {
- this.applicationClassLoader = classLoader;
+ return with( classLoader );
+ }
+
+ /**
+ * Adds a provided {@link ClassLoader} for use in class-loading and resource-lookup
+ *
+ * @param classLoader The class loader to use
+ *
+ * @return {@code this}, for method chaining
+ */
+ public BootstrapServiceRegistryBuilder with(ClassLoader classLoader) {
+ if ( providedClassLoaders == null ) {
+ providedClassLoaders = new ArrayList<ClassLoader>();
+ }
+ providedClassLoaders.add( classLoader );
+ return this;
+ }
+
+
+ /**
+ * Adds a provided {@link ClassLoaderService} for use in class-loading and resource-lookup
+ *
+ * @param classLoaderService The class loader to use
+ *
+ * @return {@code this}, for method chaining
+ */
+ public BootstrapServiceRegistryBuilder with(ClassLoaderService classLoaderService) {
+ providedClassLoaderService = classLoaderService;
return this;
}
+
/**
* Applies the specified {@link ClassLoader} as the resource class loader for the bootstrap registry
*
* @param classLoader The class loader to use
* @return {@code this}, for method chaining
+ *
+ * @deprecated Use {@link #with(ClassLoader)} instead
*/
+ @Deprecated
@SuppressWarnings( {"UnusedDeclaration"})
public BootstrapServiceRegistryBuilder withResourceClassLoader(ClassLoader classLoader) {
- this.resourcesClassLoader = classLoader;
- return this;
+ return with( classLoader );
}
/**
* Applies the specified {@link ClassLoader} as the Hibernate class loader for the bootstrap registry
*
* @param classLoader The class loader to use
* @return {@code this}, for method chaining
+ *
+ * @deprecated Use {@link #with(ClassLoader)} instead
*/
@SuppressWarnings( {"UnusedDeclaration"})
+ @Deprecated
public BootstrapServiceRegistryBuilder withHibernateClassLoader(ClassLoader classLoader) {
- this.hibernateClassLoader = classLoader;
- return this;
+ return with( classLoader );
}
/**
* Applies the specified {@link ClassLoader} as the environment (or system) class loader for the bootstrap registry
*
* @param classLoader The class loader to use
* @return {@code this}, for method chaining
+ *
+ * @deprecated Use {@link #with(ClassLoader)} instead
*/
@SuppressWarnings( {"UnusedDeclaration"})
+ @Deprecated
public BootstrapServiceRegistryBuilder withEnvironmentClassLoader(ClassLoader classLoader) {
- this.environmentClassLoader = classLoader;
- return this;
+ return with( classLoader );
}
/**
@@ -110,12 +148,12 @@ public BootstrapServiceRegistryBuilder withEnvironmentClassLoader(ClassLoader cl
* @return The built bootstrap registry
*/
public BootstrapServiceRegistry build() {
- final ClassLoaderServiceImpl classLoaderService = new ClassLoaderServiceImpl(
- applicationClassLoader,
- resourcesClassLoader,
- hibernateClassLoader,
- environmentClassLoader
- );
+ final ClassLoaderService classLoaderService;
+ if ( providedClassLoaderService == null ) {
+ classLoaderService = new ClassLoaderServiceImpl( providedClassLoaders );
+ } else {
+ classLoaderService = providedClassLoaderService;
+ }
final IntegratorServiceImpl integratorService = new IntegratorServiceImpl(
providedIntegrators,
Oops, something went wrong.

0 comments on commit a6c4640

Please sign in to comment.