Steve Ebersole edited a comment on Sub-task HHH-8010

I assume you mean that the app tries to use the org.hibernate.boot.registry.BootstrapServiceRegistryBuilder. Given that assumption...

I think that org.hibernate.boot.registry.BootstrapServiceRegistryBuilder is the correct place to integrate this via a static field. I can see 2 different ways this could work, depending on which is more "natural" in a OSGi environment:

1) org.hibernate.boot.registry.BootstrapServiceRegistryBuilder contain a static field to hold the "base" set of ClassLoader instances to use for org.hibernate.boot.registry.BootstrapServiceRegistryBuilder#providedClassLoaders. So when a user in OSGi tries to build a BootstrapServiceRegistry via BootstrapServiceRegistryBuilder, BootstrapServiceRegistryBuilder picks up the static ones (put there by the OSGi integration):

BootstrapServiceRegistry.java
public class BootstrapServiceRegistryBuilder {
    public static ClassLoader[] environmentSuppliedClassLoaders;

    ...


    public BootstrapServiceRegistry build() {
        final ClassLoaderService classLoaderService;
        if ( providedClassLoaderService == null ) {
            final List<ClassLoader> classLoaders = new ArrayList<ClassLoader>();
            if ( environmentSuppliedClassLoaders != null ) {
                classLoaders.addAll( Arrays.asList( environmentSuppliedClassLoaders ) );
            }
            if ( providedClassLoaders != null )  {
                classLoaders.addAll( providedClassLoaders );
            }
            classLoaderService = new ClassLoaderServiceImpl( classLoaders );
        }
        else {
            classLoaderService = providedClassLoaderService;
        }

        ...
    }
}

This may or may not lead to ClassLoader leak problems, have not thought through it deeply yet (brain-storming, you know). Another slight variation of this would be to have the BootstrapServiceRegistryBuilder check with the "OSGi integration" (where ever appropriate) for this static list of ClassLoaders:

BootstrapServiceRegistry.java
public class BootstrapServiceRegistryBuilder {
    ...

    public BootstrapServiceRegistry build() {
        final ClassLoaderService classLoaderService;
        if ( providedClassLoaderService == null ) {
            final List<ClassLoader> classLoaders = new ArrayList<ClassLoader>();

            // check with the OSGi integration (names made up to protect the innocent)...
            final List<ClassLoader> osgiDefinedClassLoaders = OsgiIntegration.getOsgiDefinedClassLoaders();
            if ( environmentSuppliedClassLoaders != null ) {
                classLoaders.addAll( environmentSuppliedClassLoaders );
            }
            if ( providedClassLoaders != null )  {
                classLoaders.addAll( providedClassLoaders );
            }
            classLoaderService = new ClassLoaderServiceImpl( classLoaders );
        }
        else {
            classLoaderService = providedClassLoaderService;
        }

        ...
    }
}

2) The second option is much the same as the above, but using the notion of the OSGi integration supplying a "provided ClassLoaderService" rather than ClassLoaders, much like org.hibernate.boot.registry.BootstrapServiceRegistryBuilder#providedClassLoaderService but again statically like above.

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira