From: Kai Moritz Date: Thu, 17 Dec 2015 01:53:38 +0000 (+0100) Subject: Sidestepped bug in Hibernate 5 X-Git-Tag: hibernate-maven-plugin-2.0.0~13 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=23668ccaa93bfbc583c1697214bae116bd9f4ef6;p=hibernate4-maven-plugin Sidestepped bug in Hibernate 5 --- 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 {