Browse Source

LocalSessionFactoryBuilder provides ClassLoader to Hibernate BootstrapServiceRegistry

Issue: SPR-13879
pull/1120/head
Juergen Hoeller 10 years ago
parent
commit
64e77de23b
  1. 8
      spring-orm-hibernate5/src/main/java/org/springframework/orm/hibernate5/LocalSessionFactoryBean.java
  2. 5
      spring-orm-hibernate5/src/main/java/org/springframework/orm/hibernate5/LocalSessionFactoryBuilder.java

8
spring-orm-hibernate5/src/main/java/org/springframework/orm/hibernate5/LocalSessionFactoryBean.java

@ -1,5 +1,5 @@ @@ -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 @@ -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;
}

5
spring-orm-hibernate5/src/main/java/org/springframework/orm/hibernate5/LocalSessionFactoryBuilder.java

@ -1,5 +1,5 @@ @@ -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 { @@ -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()));
}
/**

Loading…
Cancel
Save