schema is now rebuild, when SQL-dialect changes
authorKai Moritz <kai@coolibri.de>
Thu, 13 Dec 2012 15:19:55 +0000 (16:19 +0100)
committerKai Moritz <kai@coolibri.de>
Thu, 13 Dec 2012 15:19:55 +0000 (16:19 +0100)
src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java

index c9d5013..d207770 100644 (file)
@@ -325,14 +325,6 @@ public class Hbm2DdlMojo extends AbstractMojo
     if (classes.isEmpty())
       throw new MojoFailureException("No annotated classes found in directory " + outputDirectory);
 
-    if (!modified)
-    {
-      getLog().info("No modified annotated classes found.");
-      getLog().info("Skipping schema generation!");
-      project.getProperties().setProperty("hibernate4.skipped", "true");
-      return;
-    }
-
     getLog().debug("Detected classes with mapping-annotations:");
     for (Class<?> annotatedClass : classes)
       getLog().debug("  " + annotatedClass.getName());
@@ -440,6 +432,33 @@ public class Hbm2DdlMojo extends AbstractMojo
       properties.setProperty(DIALECT, hibernateDialect);
     }
 
+    /** The generated SQL varies with the dialect! */
+    if (md5s.containsKey(DIALECT))
+    {
+      String dialect = properties.getProperty(DIALECT);
+      if (md5s.get(DIALECT).equals(dialect))
+        getLog().debug("SQL-dialect unchanged.");
+      else
+      {
+        getLog().debug("SQL-dialect changed: " + dialect);
+        modified = true;
+        md5s.put(DIALECT, dialect);
+      }
+    }
+    else
+    {
+      modified = true;
+      md5s.put(DIALECT, properties.getProperty(DIALECT));
+    }
+
+    if (!modified)
+    {
+      getLog().info("No modified annotated classes found and dialect unchanged.");
+      getLog().info("Skipping schema generation!");
+      project.getProperties().setProperty("hibernate4.skipped", "true");
+      return;
+    }
+
     getLog().info("Gathered hibernate-configuration (turn on debugging for details):");
     if (properties.isEmpty())
     {