diff --git a/spring-orm-hibernate5/src/main/java/org/springframework/orm/hibernate5/LocalSessionFactoryBean.java b/spring-orm-hibernate5/src/main/java/org/springframework/orm/hibernate5/LocalSessionFactoryBean.java index aef0311f75e..08f2d8f3f50 100644 --- a/spring-orm-hibernate5/src/main/java/org/springframework/orm/hibernate5/LocalSessionFactoryBean.java +++ b/spring-orm-hibernate5/src/main/java/org/springframework/orm/hibernate5/LocalSessionFactoryBean.java @@ -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; } diff --git a/spring-orm-hibernate5/src/main/java/org/springframework/orm/hibernate5/LocalSessionFactoryBuilder.java b/spring-orm-hibernate5/src/main/java/org/springframework/orm/hibernate5/LocalSessionFactoryBuilder.java index f49b2f283d3..a4bb59e74f0 100644 --- a/spring-orm-hibernate5/src/main/java/org/springframework/orm/hibernate5/LocalSessionFactoryBuilder.java +++ b/spring-orm-hibernate5/src/main/java/org/springframework/orm/hibernate5/LocalSessionFactoryBuilder.java @@ -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())); } /**