Skip to content

Commit 64e77de

Browse files
committed
LocalSessionFactoryBuilder provides ClassLoader to Hibernate BootstrapServiceRegistry
Issue: SPR-13879
1 parent 64ce8a8 commit 64e77de

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -344,7 +344,11 @@ public void setMetadataSources(MetadataSources metadataSources) {
344344
*/
345345
public MetadataSources getMetadataSources() {
346346
if (this.metadataSources == null) {
347-
this.metadataSources = new MetadataSources(new BootstrapServiceRegistryBuilder().build());
347+
BootstrapServiceRegistryBuilder builder = new BootstrapServiceRegistryBuilder();
348+
if (this.resourcePatternResolver != null) {
349+
builder = builder.applyClassLoader(this.resourcePatternResolver.getClassLoader());
350+
}
351+
this.metadataSources = new MetadataSources(builder.build());
348352
}
349353
return this.metadataSources;
350354
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -118,7 +118,8 @@ public LocalSessionFactoryBuilder(DataSource dataSource, ClassLoader classLoader
118118
* @param resourceLoader the ResourceLoader to load application classes from
119119
*/
120120
public LocalSessionFactoryBuilder(DataSource dataSource, ResourceLoader resourceLoader) {
121-
this(dataSource, resourceLoader, new MetadataSources(new BootstrapServiceRegistryBuilder().build()));
121+
this(dataSource, resourceLoader, new MetadataSources(
122+
new BootstrapServiceRegistryBuilder().applyClassLoader(resourceLoader.getClassLoader()).build()));
122123
}
123124

124125
/**

0 commit comments

Comments
 (0)