From 23668ccaa93bfbc583c1697214bae116bd9f4ef6 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Thu, 17 Dec 2015 02:53:38 +0100 Subject: [PATCH 1/1] Sidestepped bug in Hibernate 5 --- .../plugins/hibernate/AbstractSchemaMojo.java | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/juplo/plugins/hibernate/AbstractSchemaMojo.java b/src/main/java/de/juplo/plugins/hibernate/AbstractSchemaMojo.java index b61d83c9..d50a1e7f 100644 --- a/src/main/java/de/juplo/plugins/hibernate/AbstractSchemaMojo.java +++ b/src/main/java/de/juplo/plugins/hibernate/AbstractSchemaMojo.java @@ -438,10 +438,13 @@ public abstract class AbstractSchemaMojo extends AbstractMojo /** Load checksums for old mapping and configuration */ tracker.load(); - /** Create a BootstrapServiceRegistry with special ClassLoader */ + /** Create the ClassLoader */ + URLClassLoader classLoader = createClassLoader(); + + /** Create a BootstrapServiceRegistry with the created ClassLoader */ BootstrapServiceRegistry bootstrapServiceRegitry = new BootstrapServiceRegistryBuilder() - .applyClassLoader(createClassLoader()) + .applyClassLoader(classLoader) .build(); ClassLoaderService classLoaderService = bootstrapServiceRegitry.getService(ClassLoaderService.class); @@ -520,7 +523,22 @@ public abstract class AbstractSchemaMojo extends AbstractMojo ); } - build((MetadataImplementor)metadataBuilder.build()); + /** + * Change class-loader of current thread. + * This is necessary, because still not all parts of Hibernate 5 use + * the newly introduced ClassLoaderService and will fail otherwise! + */ + Thread thread = Thread.currentThread(); + ClassLoader contextClassLoader = thread.getContextClassLoader(); + try + { + thread.setContextClassLoader(classLoader); + build((MetadataImplementor)metadataBuilder.build()); + } + finally + { + thread.setContextClassLoader(contextClassLoader); + } } finally { -- 2.20.1