Fixed NullPointerException, when dialect is specified in properties-file
authorKai Moritz <km@juplo.de>
Mon, 27 Oct 2014 08:04:48 +0000 (09:04 +0100)
committerKai Moritz <km@juplo.de>
Tue, 28 Oct 2014 13:11:10 +0000 (14:11 +0100)
Also added an integration test-case, that proofed, that the error was
solved.

src/it/properties/h2.sql [new file with mode: 0644]
src/it/properties/pom.xml [new file with mode: 0644]
src/it/properties/src/main/java/de/juplo/plugins/hibernate4/tests/SimplestMavenHib4Test.java [new file with mode: 0644]
src/it/properties/src/main/resources/hibernate.properties [new file with mode: 0644]
src/it/properties/verify.bsh [new file with mode: 0644]
src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java

diff --git a/src/it/properties/h2.sql b/src/it/properties/h2.sql
new file mode 100644 (file)
index 0000000..9569fa6
--- /dev/null
@@ -0,0 +1,12 @@
+
+    drop table test_simple if exists;
+
+    create table test_simple (
+        uuid varchar(36) not null,
+        content clob,
+        externalid varchar(148),
+        sources varchar(255),
+        primary key (uuid)
+    );
+
+    create index idx_test_simple_tuple on test_simple (sources, uuid);
diff --git a/src/it/properties/pom.xml b/src/it/properties/pom.xml
new file mode 100644 (file)
index 0000000..f3a6fc7
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>de.juplo</groupId>
+  <artifactId>hibernate4-properties-test</artifactId>
+  <name>Hibernate 4 Test - Dialect in properties-file</name>
+  <version>0.1-SNAPSHOT</version>
+  <packaging>jar</packaging>
+  <properties>
+    <!--hibernate.skip>false</hibernate.skip-->
+  </properties>
+  <dependencies>
+    <dependency>
+      <groupId>org.hibernate</groupId>
+      <artifactId>hibernate-core</artifactId>
+      <version>4.3.0.Final</version>
+    </dependency>
+  </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>2.0.2</version>
+        <configuration>
+          <source>1.7</source>
+          <target>1.7</target>
+          <encoding>utf8</encoding>
+          <showWarnings>true</showWarnings>
+        </configuration>
+      </plugin>
+      <!--  Generate database schema files -->
+      <plugin>
+        <groupId>de.juplo</groupId>
+        <artifactId>hibernate4-maven-plugin</artifactId>
+        <version>@project.version@</version>
+        <configuration>
+          <!-- Target of none generates schema only, no DB connection -->
+          <target>none</target>
+          <!-- Generate both CREATE and DROP statements in scripts -->
+          <type>both</type>
+        </configuration>
+        <executions>
+          <execution>
+            <goals>
+              <goal>export</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git a/src/it/properties/src/main/java/de/juplo/plugins/hibernate4/tests/SimplestMavenHib4Test.java b/src/it/properties/src/main/java/de/juplo/plugins/hibernate4/tests/SimplestMavenHib4Test.java
new file mode 100644 (file)
index 0000000..3a3f565
--- /dev/null
@@ -0,0 +1,32 @@
+package de.juplo.plugins.hibernate4.tests;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Lob;
+import javax.persistence.Table;
+
+import org.hibernate.annotations.Index;
+
+@Entity
+@Table(name = "test_simple")
+@org.hibernate.annotations.Table(
+        appliesTo="test_simple",
+        indexes = {
+            @Index(name="idx_test_simple_tuple", columnNames={"sources", "uuid"} ),
+        }
+)
+public class SimplestMavenHib4Test {
+
+    private String sources;
+
+    @Lob
+    private String content;
+
+    @Id
+    @Column (length=36)
+    private String uuid;
+
+    @Column(name = "externalid", length=148)
+    private String externalXyzId;
+}
diff --git a/src/it/properties/src/main/resources/hibernate.properties b/src/it/properties/src/main/resources/hibernate.properties
new file mode 100644 (file)
index 0000000..0db8712
--- /dev/null
@@ -0,0 +1 @@
+hibernate.dialect=org.hibernate.dialect.H2Dialect
diff --git a/src/it/properties/verify.bsh b/src/it/properties/verify.bsh
new file mode 100644 (file)
index 0000000..0dfcefe
--- /dev/null
@@ -0,0 +1,7 @@
+import de.juplo.test.FileComparator;
+
+
+FileComparator comparator = new FileComparator(basedir);
+
+if (!comparator.isEqual("h2.sql","target/schema.sql"))
+  return false;
index 73f0ab0..fa4ce6a 100644 (file)
@@ -598,6 +598,10 @@ public class Hbm2DdlMojo extends AbstractMojo
             );
       properties.setProperty(DIALECT, hibernateDialect);
     }
+    else
+    {
+      hibernateDialect = properties.getProperty(DIALECT);
+    }
     if ( hibernateNamingStrategy != null )
     {
       if ( properties.contains(NAMING_STRATEGY))