LocalSessionFactoryBuilder provides ClassLoader to Hibernate BootstrapServiceRegistry

Issue: SPR-13879
This commit is contained in:
Juergen Hoeller 2016-01-25 21:02:41 +01:00
parent 64ce8a81c3
commit 64e77de23b
2 changed files with 9 additions and 4 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -344,7 +344,11 @@ public class LocalSessionFactoryBean extends HibernateExceptionTranslator
*/
public MetadataSources getMetadataSources() {
if (this.metadataSources == null) {
this.metadataSources = new MetadataSources(new BootstrapServiceRegistryBuilder().build());
BootstrapServiceRegistryBuilder builder = new BootstrapServiceRegistryBuilder();
if (this.resourcePatternResolver != null) {
builder = builder.applyClassLoader(this.resourcePatternResolver.getClassLoader());
}
this.metadataSources = new MetadataSources(builder.build());
}
return this.metadataSources;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -118,7 +118,8 @@ public class LocalSessionFactoryBuilder extends Configuration {
* @param resourceLoader the ResourceLoader to load application classes from
*/
public LocalSessionFactoryBuilder(DataSource dataSource, ResourceLoader resourceLoader) {
this(dataSource, resourceLoader, new MetadataSources(new BootstrapServiceRegistryBuilder().build()));
this(dataSource, resourceLoader, new MetadataSources(
new BootstrapServiceRegistryBuilder().applyClassLoader(resourceLoader.getClassLoader()).build()));
}
/**