From 4ea068f2e9aa78e899a51e30d4caa79d0f188f88 Mon Sep 17 00:00:00 2001 From: Brett Meyer Date: Fri, 25 Apr 2014 11:53:11 -0400 Subject: [PATCH] HHH-8818 TcclSafeAggregatedClassLoader --- .../internal/ClassLoaderServiceImpl.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/hibernate-core/src/main/java/org/hibernate/boot/registry/classloading/internal/ClassLoaderServiceImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/registry/classloading/internal/ClassLoaderServiceImpl.java index 050c2586fa..9fb95e3b6b 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/registry/classloading/internal/ClassLoaderServiceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/registry/classloading/internal/ClassLoaderServiceImpl.java @@ -387,7 +387,8 @@ public class ClassLoaderServiceImpl implements ClassLoaderService { boolean set = false; try { - Thread.currentThread().setContextClassLoader( aggregatedClassLoader ); + Thread.currentThread().setContextClassLoader( + new TcclSafeAggregatedClassLoader( aggregatedClassLoader, tccl ) ); set = true; } catch (Exception ignore) { @@ -403,5 +404,30 @@ public class ClassLoaderServiceImpl implements ClassLoaderService { } } + + // TODO: Remove in ORM 5! See HHH-8818 + private class TcclSafeAggregatedClassLoader extends ClassLoader { + private final AggregatedClassLoader aggregatedClassLoader; + + private TcclSafeAggregatedClassLoader(AggregatedClassLoader aggregatedClassLoader, ClassLoader tccl) { + super(tccl); + this.aggregatedClassLoader = aggregatedClassLoader; + } + + @Override + public Enumeration getResources(String name) throws IOException { + return aggregatedClassLoader.getResources( name ); + } + + @Override + protected URL findResource(String name) { + return aggregatedClassLoader.findResource( name ); + } + + @Override + protected Class findClass(String name) throws ClassNotFoundException { + return aggregatedClassLoader.findClass( name ); + } + } }