From 524cb8c971de87c21d0d9f0e04edf6bd30f77acc Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sat, 9 May 2015 23:48:39 +0200 Subject: [PATCH] Be sure to relase all resources (closing db-connections!) --- .../java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java b/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java index 3efa1852..aebf02e5 100644 --- a/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java +++ b/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java @@ -541,8 +541,11 @@ public class Hbm2DdlMojo extends AbstractMojo // Clear unused system-properties config.setProperties(new Properties()); + ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); + StandardServiceRegistryImpl registry = null; MavenLogAppender.startPluginLog(this); + try { /** Try to read configuration from properties-file */ @@ -897,7 +900,7 @@ public class Hbm2DdlMojo extends AbstractMojo Environment.verifyProperties(config.getProperties()); ConfigurationHelper.resolvePlaceHolders(config.getProperties()); - StandardServiceRegistryImpl registry = + registry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder() .applySettings(config.getProperties()) @@ -952,6 +955,9 @@ public class Hbm2DdlMojo extends AbstractMojo /** Restore the old class-loader (TODO: is this really necessary?) */ Thread.currentThread().setContextClassLoader(contextClassLoader); + + if (registry != null) + registry.destroy(); } /** Write md5-sums for annotated classes to file */ -- 2.20.1