From 1628bcf6c9290a729352215ee22e5b48fa628c4c Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Tue, 29 Apr 2014 18:07:44 +0200 Subject: [PATCH 01/16] Verifying generated SQL in integration-test hibernate4-maven-plugin-envers-sample --- .../create-tables-hsqldb.sql | 33 +++++++++++++++++++ .../drop-tables-hsqldb.sql | 10 ++++++ .../verify.bsh | 9 +++++ 3 files changed, 52 insertions(+) create mode 100644 src/it/hibernate4-maven-plugin-envers-sample/create-tables-hsqldb.sql create mode 100644 src/it/hibernate4-maven-plugin-envers-sample/drop-tables-hsqldb.sql create mode 100644 src/it/hibernate4-maven-plugin-envers-sample/verify.bsh diff --git a/src/it/hibernate4-maven-plugin-envers-sample/create-tables-hsqldb.sql b/src/it/hibernate4-maven-plugin-envers-sample/create-tables-hsqldb.sql new file mode 100644 index 00000000..fe6130e0 --- /dev/null +++ b/src/it/hibernate4-maven-plugin-envers-sample/create-tables-hsqldb.sql @@ -0,0 +1,33 @@ + + create table TTL_AUDIT_REVISION ( + ID bigint not null, + EVENT_DATE timestamp, + ENVERS_TSTAMP bigint not null, + USER_NAME varchar(80) not null, + primary key (ID) + ); + + create table TTL_EVENT ( + ID bigint not null, + EVENT_DATE timestamp not null, + TITLE varchar(80) not null, + primary key (ID) + ); + + create table TTL_EVENT_AUD ( + ID bigint not null, + REV bigint not null, + REVTYPE tinyint, + EVENT_DATE timestamp, + TITLE varchar(80), + primary key (ID, REV) + ); + + alter table TTL_EVENT_AUD + add constraint FK_cjsh8995uabmdm9b30uvmyj6p + foreign key (REV) + references TTL_AUDIT_REVISION; + + create sequence TTL_AUDIT_REVISION_SEQ; + + create sequence TTL_EVENT_SEQ; diff --git a/src/it/hibernate4-maven-plugin-envers-sample/drop-tables-hsqldb.sql b/src/it/hibernate4-maven-plugin-envers-sample/drop-tables-hsqldb.sql new file mode 100644 index 00000000..1578d898 --- /dev/null +++ b/src/it/hibernate4-maven-plugin-envers-sample/drop-tables-hsqldb.sql @@ -0,0 +1,10 @@ + drop table TTL_AUDIT_REVISION if exists cascade; + + drop table TTL_EVENT if exists cascade; + + drop table TTL_EVENT_AUD if exists cascade; + + drop sequence TTL_AUDIT_REVISION_SEQ if exists ; + + drop sequence TTL_EVENT_SEQ if exists ; + diff --git a/src/it/hibernate4-maven-plugin-envers-sample/verify.bsh b/src/it/hibernate4-maven-plugin-envers-sample/verify.bsh new file mode 100644 index 00000000..125f4042 --- /dev/null +++ b/src/it/hibernate4-maven-plugin-envers-sample/verify.bsh @@ -0,0 +1,9 @@ +import de.juplo.test.FileComparator; + + +FileComparator comparator = new FileComparator(basedir); + +if (!comparator.isEqual("create-tables-hsqldb.sql","target/test-classes/sql/create-tables-hsqldb.sql")) + return false; +if (!comparator.isEqual("drop-tables-hsqldb.sql","target/test-classes/sql/drop-tables-hsqldb.sql")) + return false; -- 2.20.1 From bd78c276663790bf7a3f121db85a0d62c64ce38c Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Tue, 29 Apr 2014 19:42:41 +0200 Subject: [PATCH 02/16] Fixed bug in site-configuration --- pom.xml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index f09a0850..a2abed65 100644 --- a/pom.xml +++ b/pom.xml @@ -282,6 +282,9 @@ maven-site-plugin 3.3 + + ${project.build.directory}/filtered-site + org.apache.maven.wagon @@ -296,13 +299,6 @@ - - maven-site-plugin - 3.3 - - ${project.build.directory}/filtered-site - - org.apache.maven.plugins maven-changes-plugin -- 2.20.1 From 64900890db2575b7a28790c5e4d5f45083ee94b3 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Tue, 29 Apr 2014 20:43:15 +0200 Subject: [PATCH 03/16] Switched documentation to xhtml, to be able to integrate google-pretty-print --- src/site/apt/configuration.apt | 214 ------------------ src/site/apt/debugging.apt | 25 -- src/site/apt/force.apt | 35 --- src/site/apt/index.apt | 59 ----- src/site/apt/issue-tracking.apt | 11 - src/site/apt/mail-lists.apt | 10 - src/site/apt/skip.apt | 55 ----- src/site/site.xml | 1 + src/site/xhtml/configuration.xhtml | 213 +++++++++++++++++ src/site/xhtml/debugging.xhtml | 30 +++ src/site/xhtml/force.xhtml | 40 ++++ src/site/xhtml/index.xhtml | 68 ++++++ src/site/xhtml/issue-tracking.xhtml | 13 ++ src/site/xhtml/mail-lists.xhtml | 13 ++ .../pitfalls.apt => xhtml/pitfalls.xhtml} | 206 +++++++++-------- src/site/xhtml/skip.xhtml | 59 +++++ 16 files changed, 539 insertions(+), 513 deletions(-) delete mode 100644 src/site/apt/configuration.apt delete mode 100644 src/site/apt/debugging.apt delete mode 100644 src/site/apt/force.apt delete mode 100644 src/site/apt/index.apt delete mode 100644 src/site/apt/issue-tracking.apt delete mode 100644 src/site/apt/mail-lists.apt delete mode 100644 src/site/apt/skip.apt create mode 100644 src/site/xhtml/configuration.xhtml create mode 100644 src/site/xhtml/debugging.xhtml create mode 100644 src/site/xhtml/force.xhtml create mode 100644 src/site/xhtml/index.xhtml create mode 100644 src/site/xhtml/issue-tracking.xhtml create mode 100644 src/site/xhtml/mail-lists.xhtml rename src/site/{apt/pitfalls.apt => xhtml/pitfalls.xhtml} (53%) create mode 100644 src/site/xhtml/skip.xhtml diff --git a/src/site/apt/configuration.apt b/src/site/apt/configuration.apt deleted file mode 100644 index 98fad3bc..00000000 --- a/src/site/apt/configuration.apt +++ /dev/null @@ -1,214 +0,0 @@ - --- - Configuration Examples - --- - Kai Moritz - --- - -Configuration through a hibernate.properties-File - - The most simple way to configure the plugin is, to put all the - hibernate-configuration in a <>-file on your - classpath. Put the file in the <<>>-folder. Maven will put - it in the <<>>-folder of your webapp, where it will be picked up - by this plugin as well as by Hibernate 4. - - Doing so, the only additionally configuration needed, to activat the plugin - is the following entry in the <<>>-section of your <<>>: - ---------------- - - de.juplo - hibernate4-maven-plugin - ${project.version} - - - - export - - - - ---------------- - - But be aware, that in this case the database-url, that is - build in the application is the same that is used while testing, where - the database is droped and recreated by the plugin. - <<>> - - Hence, you should specify a different url for testing like in the - following snippet: - ---------------- - - de.juplo - hibernate4-maven-plugin - ${project.version} - - - - export - - - - - - - ---------------- - - Configuration properties, that are set in the <<>>-section - of the plugin-configuration cannnot be overwritten elsewere (for details - see {{Configuration-Method-Precedence}}). - You never can overwrite them by accident when specifying a property on - the commandline or in your <<>>. - -Configuration through maven-properties - - Alternatively, it is possible, to configure the plugin via maven-properties. - Each relevant configuration-option has a corresponding maven-property - (for a full list see the {{{./export-mojo.html} Documentation of the export-Mojo}}). - These are named after the - {{{http://docs.jboss.org/hibernate/orm/4.1/manual/en-US/html_single/#configuration-hibernatejdbc} Hibernate JDBC Properties}}: - - * <<>> - - * <<>> - - * <<>> - - * <<>> - - * <<>> - - So, instead of writing the hibernate-configuration in the properties-file, - like above, you could put it in the <<>>-section of your - <<>>. - - Thogether with the plugin-definition from above, the following would - be a complete configuration (again, the database-url was overwritten in - the plugin-configuration, to be sure to have a separate database for - testing): - ---------------- - - org.hsqldb.jdbcDriver - org.hibernate.dialect.HSQLDialect - - sa - - - -... - - - - ... - - - de.juplo - hibernate4-maven-plugin - ${project.version} - - - - export - - - - - - - - - ---------------- - -Configuration through the plugin-configuration - - A third way for configuring the plugin is the plugin-configuration. - The relevant configuration-parameters are: - - * <<>> - - * <<>> - - * <<>> - - * <<>> - - * <<>> - - The equivalent of the configuration from the last section would look - like this: - ---------------- - - de.juplo - hibernate4-maven-plugin - ${project.version} - - - - export - - - - - org.hsqldb.jdbcDriver - org.hibernate.dialect.HSQLDialect - - sa - - - ---------------- - - The parameter <> (name of the hibernate-properties-file - to use, defaults to <>) can only be configured through - this approach. - - For more explanations, see the - {{{./export-mojo.html} Documentation of the export-Mojo}}. - -{Configuration-Method-Precedence} - - The configuration is gathered in a fix order: - - [[1]] <<>> - - [[2]] maven-properties - - [[3]] plugin-configuration - - If you are in doubt about where a configuration-value comes from, run - maven with the {{{./debugging.html}debug-output}} enabled: <<>> - and be aware, that maven-properties can be overwitten on the command-line, - in your <<<~/.m2/settings.xml>>> and in a profile. - - The plugin-configuration comes last and overwrites everything else. - That way, you can be sure, that a configuration-value, that is - specified in the plugin-configuration will never be overwritten by any - other configuration-method. - - - If you realy need to overwrite plugin-configuration-values with - maven-properties, you can use maven-properties in the plugin-configuration: - ----------------- - - de.juplo - hibernate4-maven-plugin - ${project.version} - - - - export - - - - - ${my-password-property} - - ----------------- diff --git a/src/site/apt/debugging.apt b/src/site/apt/debugging.apt deleted file mode 100644 index 37e81186..00000000 --- a/src/site/apt/debugging.apt +++ /dev/null @@ -1,25 +0,0 @@ - --- - Enabling Debug-Output - --- - Kai Moritz - --- - - If you are new to <<>>, in many cases, the - {Configuration-Method-Precedence} may be the source of configuration - errors. - To solve this problem, you should run maven with the debugging output - enabled. - For example, by executing: - -------------- -mvn -X compile hibernate4:export -------------- - - (The <<>> might be necessary, because <<>> - has to scan the compiled classes for annotations!) - - Unlike the majority of the maven-plugins, <<>> was - designed to give a good many hints, when debugging is enabled. - Because, if you do not know, what went wrong, you can't fix it! - - <> <<>> tends to be very chatty ;) diff --git a/src/site/apt/force.apt b/src/site/apt/force.apt deleted file mode 100644 index bff87d87..00000000 --- a/src/site/apt/force.apt +++ /dev/null @@ -1,35 +0,0 @@ - --- - Force execution - --- - Kai Moritz - --- - - The hibernate4-maven-plugin computes MD5-sums for all found annotated - classes and stores them together with the generated schema. - If no classes were changed or added and the dialect wasn't changed too, it - automatically skips the configured schema-export, to speed up the development - cycle. - - The plugin signals, that the execution was skipped by setting the maven - property <<<${hibernate.export.skipped}>>> to <<>>. - This may be helpful, because other plugins like - {{{http://mojo.codehaus.org/dbunit-maven-plugin/}dbunit-plugin}} - {{{./pitfalls.html#fails}may fail}}, when the execution is skipped. - - If you need the hibernate4-maven-plugin to , - you can force it to do so, if you set the parameter <<>> to - <<>>: - ----------------- - - de.juplo - hibernate4-maven-plugin - ${project.version} - - true - - ----------------- - - Or you may specify <<<-Dhibernate.export.force=true>>> at the command line, - if you want to force hibernate4-maven-plugin only once. diff --git a/src/site/apt/index.apt b/src/site/apt/index.apt deleted file mode 100644 index 76af6732..00000000 --- a/src/site/apt/index.apt +++ /dev/null @@ -1,59 +0,0 @@ - --- - A simple Plugin for generating a Database-Schema from Hibernate 4 Mapping-Annotations. - --- - Kai Moritz - --- - - <> is a plugin for generating a database-schema - from your Hibernate-4-Mappings and create or update your database - accordingly. - Its main usage is to automatically create and populate a test-database - for unit-tests in cooperation with the - {{{http://mojo.codehaus.org/dbunit-maven-plugin/} dbunit-maven-plugin}}. - - The plugin was designed with three main goals in mind: - - * It should be easy to use. - - * It should be maximal unlikely, to erase a producation-database by - accident. - - * It should not slow down the development cycle. - - To achieve the first goal, the convention-over-configuration paradigma - was applied and the plugin was stuffed with usefull logging-messages. - So, if in doubt, just turn on the {{{./debugging.html} debugging output}} with the <<>>. - - To achieve the second goal, the precedence in which the configuration - locations are consulted was layouted in a way that makes it possible, to - prevent overwrites of the wrong database by accident. - - Last but not least, in order to not slow down the development cycle, the - hibernate4-maven-plugin only executes the schema-export, if the mapping - or the dialect changes (or if you force it to do so). - - For more information about the inspiration to write this tiny plugin, - {{{/hibernate4-maven-plugin-a-simple-plugin-for-generating-a-database-schema-from-hibernate-4-mapping-annotations/} read our blog-article about the hibernate4-maven-plugin}}. - -Documentation - - * See {{{./configuration.html} Configuration Examples}} for Usage-Explanations - and simple examples of how to use this plugin. - - * See {{{./export-mojo.html}hibernate4:export}} and - {{{./plugin-info.html} Plugin Documentation}} for the full - autogenerated documentation. These are mostly configuration-options - of the Hibernate-Tools <<>> and <<>>, that do - the work in the background. - -Releases - - * {{{http://juplo.de/hibernate4-maven-plugin} current version}} - - * ${project.version} (this version) - - * {{{http://juplo.de/hibernate4-maven-plugin-1.0.2} 1.0.2}} - - * {{{http://juplo.de/hibernate4-maven-plugin-1.0.1} 1.0.1}} - - * {{{http://juplo.de/hibernate4-maven-plugin-1.0} 1.0}} diff --git a/src/site/apt/issue-tracking.apt b/src/site/apt/issue-tracking.apt deleted file mode 100644 index 42292e1a..00000000 --- a/src/site/apt/issue-tracking.apt +++ /dev/null @@ -1,11 +0,0 @@ - --- - Issue Tracking - --- - Kai Moritz - ---- - - <> - - Please send your bug-reports, questions or feature-requests directly - to the developer. - diff --git a/src/site/apt/mail-lists.apt b/src/site/apt/mail-lists.apt deleted file mode 100644 index e8c17ec5..00000000 --- a/src/site/apt/mail-lists.apt +++ /dev/null @@ -1,10 +0,0 @@ - --- - Mailing Lists - --- - Kai Moritz - --- - - <> - - Please send your bug-reports, questions or feature-requests directly - to the developer. diff --git a/src/site/apt/skip.apt b/src/site/apt/skip.apt deleted file mode 100644 index 676a7def..00000000 --- a/src/site/apt/skip.apt +++ /dev/null @@ -1,55 +0,0 @@ - --- - To Skip or not to skip: that is the question - --- - Kai Moritz - --- - - In most use-cases, the hibernate4-maven-plugin is used to create a - test-database automatically. In this use-cases, it is very likely, that it - will result in mistakes/errors, if the goal is executed, when the tests - are skipped. - For example, one might manually overwrite the database-url with the url of - the production-database, in order to run other tests, like starting a - local webserver with the - {{{http://wiki.eclipse.org/Jetty/Feature/Jetty_Maven_Plugin}jetty-maven-plugin}}. - If the export-goal would be executed in such a scenario, it might erase the - hole production-database, which is not very desireable. - - Because of this, the configuration-parameter <<>> defaults to the value - of the proptery <<>>. This way, the execution of the - hibernate4-maven-plugin is skipped automatically, when the tests are - skipped. Think of it as a build-in security-belt. - - If you do not like that, because you need the plugin to always execute the - export-goal, even if the tests are skipped you can configure that explicitly, - by setting the configuration-parameter <<>> to false: - ------------- - - de.juplo - hibernate4-maven-plugin - ... - - false - - ------------- - - Or, if you want the export-goal to be executed by default and to be skipped - if you say so, you can bind the value of the configuration-parameter - <<>> to a custom property. For example: - ------------- - - de.juplo - hibernate4-maven-plugin - ... - - ${foo.bar} - - ------------- - - This way, the export-goal would be skipped, if you set the property - <<>> to <<>>. For example, if you specify <<<-Dfoo.bar=true>>> - on the command-line. diff --git a/src/site/site.xml b/src/site/site.xml index f3e19969..5399d177 100644 --- a/src/site/site.xml +++ b/src/site/site.xml @@ -14,6 +14,7 @@ de.juplo juplo-maven-skin + 1.0.7 diff --git a/src/site/xhtml/configuration.xhtml b/src/site/xhtml/configuration.xhtml new file mode 100644 index 00000000..bfaf6fec --- /dev/null +++ b/src/site/xhtml/configuration.xhtml @@ -0,0 +1,213 @@ + + + + + + +

Configuration through a hibernate.properties-File

+

+ The most simple way to configure the plugin is, to put all the + hibernate-configuration in a hibernate.properties-file on your + classpath. Put the file in the resources-folder. Maven will put + it in the class-folder of your webapp, where it will be picked up + by this plugin as well as by Hibernate 4. +

+

+ Doing so, the only additionally configuration needed, to activat the plugin + is the following entry in the plugins-section of your pom.xml: +

+
+<plugin>
+  <groupId>de.juplo</groupId>
+  <artifactId>hibernate4-maven-plugin</artifactId>
+  <version>${project.version}</version>
+  <executions>
+    <execution>
+      <goals>
+        <goal>export</goal>
+      </goals>
+    </execution>
+  </executions>
+</plugin>
+

+ But be aware, that in this case the database-url, that is + build in the application is the same that is used while testing, where + the database is droped and recreated by the plugin. + + So, you should never fire up this configuration on your production + system, or your database might be erased! + +

+

+ Hence, you should specify a different url for testing like in the + following snippet: +

+
+<plugin>
+  <groupId>de.juplo</groupId>
+  <artifactId>hibernate4-maven-plugin</artifactId>
+  <version>${project.version}</version>
+  <executions>
+    <execution>
+      <goals>
+        <goal>export</goal>
+      </goals>
+    </execution>
+  </executions>
+  <configuration>
+    <url><![CDATA[jdbc:mysql://localhost/test-db]]></url>
+  </configuration>
+</plugin>
+

+ Configuration properties, that are set in the configuration-section + of the plugin-configuration cannnot be overwritten elsewere (for details + see Configuration-Method-Precedence). + You never can overwrite them by accident when specifying a property on + the commandline or in your settings.xml. +

+

Configuration through maven-properties

+

+ Alternatively, it is possible, to configure the plugin via maven-properties. + Each relevant configuration-option has a corresponding maven-property + (for a full list see the Documentation of the export-Mojo). + These are named after the + Hibernate JDBC Properties: +

+
    +
  • hibernate.connection.driver_class
  • +
  • hibernate.dialect
  • +
  • hibernate.connection.url
  • +
  • hibernate.connection.username
  • +
  • hibernate.connection.password
  • +
+

+ So, instead of writing the hibernate-configuration in the properties-file, + like above, you could put it in the properties-section of your + pom.xml. +

+

+ Thogether with the plugin-definition from above, the following would + be a complete configuration (again, the database-url was overwritten in + the plugin-configuration, to be sure to have a separate database for + testing): +

+
+<properties>
+  <hibernate.connection.driver_class>org.hsqldb.jdbcDriver</hibernate.connection.driver_class>
+  <hibernate.dialect>org.hibernate.dialect.HSQLDialect</hibernate.dialect>
+  <hibernate.connection.url><![CDATA[jdbc:hsqldb:res:org.my.path.production_db]]></hibernate.connection.url>
+  <hibernate.connection.username>sa</hibernate.connection.username>
+  <hibernate.connection.password></hibernate.connection.password>
+</properties>
+
+...
+
+<plugins>
+
+  ...
+
+  <plugin>
+    <groupId>de.juplo</groupId>
+    <artifactId>hibernate4-maven-plugin</artifactId>
+    <version>${project.version}</version>
+    <executions>
+      <execution>
+        <goals>
+          <goal>export</goal>
+        </goals>
+      </execution>
+    </executions>
+    <configuration>
+      <url><![CDATA[jdbc:hsqldb:target/db/testdb;shutdown=true]]></url>
+    </configuration>
+  </plugin>
+
+<plugins>
+

Configuration through the plugin-configuration

+

+ A third way for configuring the plugin is the plugin-configuration. + The relevant configuration-parameters are: +

+
    +
  • driverClassName
  • +
  • hibernateDialect
  • +
  • url
  • +
  • username
  • +
  • password
  • +
+

+ The equivalent of the configuration from the last section would look + like this: +

+
+<plugin>
+  <groupId>de.juplo</groupId>
+  <artifactId>hibernate4-maven-plugin</artifactId>
+  <version>${project.version}</version>
+  <executions>
+    <execution>
+      <goals>
+        <goal>export</goal>
+      </goals>
+    </execution>
+  </executions>
+  <configuration>
+    <driverClassName>org.hsqldb.jdbcDriver</driverClassName>
+    <hibernateDialect>org.hibernate.dialect.HSQLDialect</hibernateDialect>
+    <url><![CDATA[jdbc:hsqldb:target/db/fotos;shutdown=true]]></url>
+    <username>sa</username>
+    <password></password>
+  </configuration>
+</plugin>
+

+ The parameter hibernateProperties (name of the hibernate-properties-file + to use, defaults to hibernate.properties) can only be configured through + this approach. +

+

+ For more explanations, see the + Documentation of the export-Mojo. +

+

Configuration-Method-Precedence

+

+ The configuration is gathered in a fix order: +

+
    +
  1. hibernate.properties
  2. +
  3. maven-properties
  4. +
  5. plugin-configuration
  6. +
+

+ If you are in doubt about where a configuration-value comes from, run + maven with the debug-output enabled: mvn -X hibernate4:export + and be aware, that maven-properties can be overwitten on the command-line, + in your ~/.m2/settings.xml and in a profile. +

+

+ The plugin-configuration comes last and overwrites everything else. + That way, you can be sure, that a configuration-value, that is + specified in the plugin-configuration will never be overwritten by any + other configuration-method. +

+

+ If you realy need to overwrite plugin-configuration-values with + maven-properties, you can use maven-properties in the plugin-configuration: +

+
+<plugin>
+  <groupId>de.juplo</groupId>
+  <artifactId>hibernate4-maven-plugin</artifactId>
+  <version>${project.version}</version>
+  <executions>
+    <execution>
+      <goals>
+        <goal>export</goal>
+      </goals>
+    </execution>
+  </executions>
+  <configuration>
+    <password>${my-password-property}</password>
+  </configuration>
+</plugin>
+ + diff --git a/src/site/xhtml/debugging.xhtml b/src/site/xhtml/debugging.xhtml new file mode 100644 index 00000000..8f91f3f9 --- /dev/null +++ b/src/site/xhtml/debugging.xhtml @@ -0,0 +1,30 @@ + + + + + + +

+ If you are new to hibernate4-maven-plugin, in many cases, the + {Configuration-Method-Precedence} may be the source of configuration + errors. + To solve this problem, you should run maven with the debugging output + enabled. + For example, by executing: +

+
+mvn -X compile hibernate4:export
+

+ (The compile might be necessary, because hibernate4-maven-plugin + has to scan the compiled classes for annotations!) +

+

+ Unlike the majority of the maven-plugins, hibernate4-maven-plugin was + designed to give a good many hints, when debugging is enabled. + Because, if you do not know, what went wrong, you can't fix it! +

+

+ But be warned: hibernate4-maven-plugin tends to be very chatty ;) +

+ + diff --git a/src/site/xhtml/force.xhtml b/src/site/xhtml/force.xhtml new file mode 100644 index 00000000..0a94070e --- /dev/null +++ b/src/site/xhtml/force.xhtml @@ -0,0 +1,40 @@ + + + + + + +

+ The hibernate4-maven-plugin computes MD5-sums for all found annotated + classes and stores them together with the generated schema. + If no classes were changed or added and the dialect wasn't changed too, it + automatically skips the configured schema-export, to speed up the development + cycle. +

+

+ The plugin signals, that the execution was skipped by setting the maven + property $\{hibernate.export.skipped\} to true. + This may be helpful, because other plugins like + dbunit-plugin + may fail, when the execution is skipped. +

+

+ If you need the hibernate4-maven-plugin to <never skip execution automatically>, + you can force it to do so, if you set the parameter force to + true: +

+
+<plugin>
+  <groupId>de.juplo</groupId>
+  <artifactId>hibernate4-maven-plugin</artifactId>
+  <version>${project.version}</version>
+  <configuration>
+    <force>true</force>
+  </configuration>
+</plugin>
+

+ Or you may specify -Dhibernate.export.force=true at the command line, + if you want to force hibernate4-maven-plugin only once. +

+ + diff --git a/src/site/xhtml/index.xhtml b/src/site/xhtml/index.xhtml new file mode 100644 index 00000000..ef7de69c --- /dev/null +++ b/src/site/xhtml/index.xhtml @@ -0,0 +1,68 @@ + + + + + + +

Hibernate 4 Maven Plugin

+

A simple Plugin for generating a Database-Schema from Hibernate 4 Mapping-Annotations

+

+ The hibernate4-maven-plugin is a plugin for generating a database-schema + from your Hibernate-4-Mappings and create or update your database + accordingly. + Its main usage is to automatically create and populate a test-database + for unit-tests in cooperation with the + dbunit-maven-plugin. +

+

+ The plugin was designed with three main goals in mind: +

+
    +
  • It should be easy to use.
  • +
  • It should be maximal unlikely, to erase a producation-database by accident.
  • +
  • It should not slow down the development cycle.
  • +
+

+ To achieve the first goal, the convention-over-configuration paradigma + was applied and the plugin was stuffed with usefull logging-messages. + So, if in doubt, just turn on the debugging output with the mvn -X .... +

+

+ To achieve the second goal, the precedence in which the configuration + locations are consulted was layouted in a way that makes it possible, to + prevent overwrites of the wrong database by accident. +

+

+ Last but not least, in order to not slow down the development cycle, the + hibernate4-maven-plugin only executes the schema-export, if the mapping + or the dialect changes (or if you force it to do so). +

+

+ For more information about the inspiration to write this tiny plugin, + read our blog-article about the hibernate4-maven-plugin. +

+

Documentation

+
    +
  • + See Configuration Examples for Usage-Explanations + and simple examples of how to use this plugin. +
  • +
  • + See hibernate4:export and + Plugin Documentation for the full + autogenerated documentation. These are mostly configuration-options + of the Hibernate-Tools SchemaExport and SchemaUpdate, that do + the work in the background. +
  • +
+

Releases

+ + + diff --git a/src/site/xhtml/issue-tracking.xhtml b/src/site/xhtml/issue-tracking.xhtml new file mode 100644 index 00000000..f7e68598 --- /dev/null +++ b/src/site/xhtml/issue-tracking.xhtml @@ -0,0 +1,13 @@ + + + + + + + There is no bug-tracking system set up for this project! +

+ Please send your bug-reports, questions or feature-requests directly + to the developer. +

+ + diff --git a/src/site/xhtml/mail-lists.xhtml b/src/site/xhtml/mail-lists.xhtml new file mode 100644 index 00000000..ff8d7f2b --- /dev/null +++ b/src/site/xhtml/mail-lists.xhtml @@ -0,0 +1,13 @@ + + + + + + + There are no mailinglists defined for this project! +

+ Please send your bug-reports, questions or feature-requests directly + to the developer. +

+ + diff --git a/src/site/apt/pitfalls.apt b/src/site/xhtml/pitfalls.xhtml similarity index 53% rename from src/site/apt/pitfalls.apt rename to src/site/xhtml/pitfalls.xhtml index 355e369e..50006953 100644 --- a/src/site/apt/pitfalls.apt +++ b/src/site/xhtml/pitfalls.xhtml @@ -1,46 +1,46 @@ - --- - Known Pitfalls - --- - Kai Moritz - --- - -Annotated classes in dependencies are not found. - + + + + + + +

Annotated classes in dependencies are not found.

+

hibernate4-maven-plugin by default scans dependencies in the scope compile. You can configure it to scan dependencies in other scopes as well. But it scans only direct dependencies. Transitive dependencies are not scanned for annotated classes. If some of your annotated classes are hidden in a transitive dependency, you can simply add that dependency explicitly. - -hibernate4-maven-plugin always needs a database-connection - +

+

hibernate4-maven-plugin always needs a database-connection

+

The default-configuration uses the EXPORT-target of the SchemaExport-Tool. If you do not need to create a database with the evaluated schema, you can use the NONE- or the SCRIPT-target. This can be achieved with the command-line parameter - <<<-Dhibernate.export.target=SCRIPT>>> or with the following configuration: - ------------- - - SCRIPT - ------------- - + -Dhibernate.export.target=SCRIPT or with the following configuration: +

+
+<configuration>
+  <target>SCRIPT</target>
+</configuration>
+

But even when no database is to be created, hibernate always needs to know the dialect. Hence, the plugin will fail if this parameter is missing! - -Dependency for driver-class XYZ is missing - +

+

Dependency for driver-class XYZ is missing

+

One regular problem is the scope of the jdbc-driver-dependency. It is very unlikely, that this dependency is needed at compile-time. - So a tidy maven-developer would usually scope it for <<>>. - - But this will break the execution of the <<>>. + So a tidy maven-developer would usually scope it for runtime. +

+

+ But this will break the execution of the hibernate4-maven-plugin. Since it will not be able to see the needed dependency, it will fail with an error-message like: - ---------------- +

+
 [INFO] Gathered hibernate-configuration (turn on debugging for details):
 [INFO]   hibernate.connection.username = sa
 [INFO]   hibernate.connection.password = 
@@ -58,76 +58,75 @@ Dependency for driver-class XYZ is missing
 [INFO] Total time: 2 seconds
 [INFO] Finished at: Thu Nov 29 11:31:14 CET 2012
 [INFO] Final Memory: 32M/342M
-[INFO] ------------------------------------------------------------------------
----------------
-
+[INFO] ------------------------------------------------------------------------
+

A quick workaround for this error would be, to delete the runtime-constraint for the jdbc-driver-dependency. - +

+

A much cleaner way is, to (additionally) ad the dependency, to the plugin-definition: - ---------------- - - de.juplo - hibernate4-maven-plugin - ${project.version} - - - - export - - - - - - org.hsqldb - hsqldb - 2.2.8 - - - ---------------- - +

+
+<plugin>
+  <groupId>de.juplo</groupId>
+  <artifactId>hibernate4-maven-plugin</artifactId>
+  <version>${project.version}</version>
+  <executions>
+    <execution>
+      <goals>
+        <goal>export</goal>
+      </goals>
+    </execution>
+  </executions>
+  <dependencies>
+  <dependency>
+    <groupId>org.hsqldb</groupId>
+    <artifactId>hsqldb</artifactId>
+    <version>2.2.8</version>
+  </dependency>
+  </dependencies>
+</plugin>
+

This is also the best way, if you use a different jdbc-driver for testing, than in production. Because otherwise, this dependency will unnecessarily bloat the runtime-dependencies of your project. - -DBUnit {fails} after execution of hibernate4 was skipped because nothing has changed - +

+

DBUnit fails after execution of hibernate4 was skipped because nothing has changed

+

If hibernate4-maven-plugin skips its excecution, this may lead to errors in other plugins. For example, when importing sample-data in the automatically created database - with the help of the {{{http://mojo.codehaus.org/dbunit-maven-plugin/}dbunit-plugin}}, - the <<>>-operation may fail because of foreign-key-constraints, + with the help of the dbunit-plugin, + the CLEAN_INSERT-operation may fail because of foreign-key-constraints, if the database was not recreated, because the hibernate4-maven-plugin has skipped its excecution. - - A quick fix to this problem is, to {{{./force.html}force}} +

+

+ A quick fix to this problem is, to force hibernate4-maven-plugin to export the schema every time it is running. But to recreate the database on every testrun may noticeable slow down your development cycle, if you have to wait for slow IO. - +

+

To circumvent this problem, hibernate4-maven-plugin signals a skipped - excecution by setting the maven property <<<${hibernate.export.skipped}>>> to - <<>>. + excecution by setting the maven property $\{hibernate.export.skipped\} to + true. You can configure other plugins to react on this signal. For example, the dbunit-plugin can be configured to skip its excecution, if hibernate4-maven-plugin was skipped like this: - ------------- - - org.codehaus.mojo - dbunit-maven-plugin - - ${hibernate.export.skipped} - - ------------- - -The database will not be recreated after a manual drop/clean - +

+
+<plugin>
+  <groupId>org.codehaus.mojo</groupId>
+  <artifactId>dbunit-maven-plugin</artifactId>
+  <configuration>
+    <skip>${hibernate.export.skipped}</skip>
+  </configuration>
+</plugin>
+

The database will not be recreated after a manual drop/clean

+

If one manually drops the database or removes the hsqldb-files, it will not be recreated by the hibernate4-maven-plugin, because it cannot detect, that the database needs to be recreated. @@ -135,35 +134,34 @@ The database will not be recreated after a manual drop/clean the configuration nor the annotated classes have changed, because an unnecessary drop-create-cycle might take a long time. The plugin will report that like this: - -------------- +

+
 [INFO] No modified annotated classes found and dialect unchanged.
-[INFO] Skipping schema generation!
--------------
-
-  If one always uses <<>> for cleanup, this will not happen.
-  Otherwise the recreation must be {{{./force.html}forced}}:
-
--------------
-mvn hibernate4:export -Dhibernate.export.force=true
--------------
-
-The hibernate4:export goal is not executed, when tests are skipped
-
+[INFO] Skipping schema generation!
+

+ If one always uses mvn clean for cleanup, this will not happen. + Otherwise the recreation must be forced: +

+
+mvn hibernate4:export -Dhibernate.export.force=true
+

The hibernate4:export goal is not executed, when tests are skipped

+

The hibernate4-maven-plugin automatically skips its execution, when - <<>> is set to <<>>. If you need it to be always + maven.test.skip is set to true. If you need it to be always executed, you can configure that explicitly like this: - ------------- - - de.juplo - hibernate4-maven-plugin +

+
+>plugin<
+  <groupId>de.juplo</groupId>
+  <artifactId>hibernate4-maven-plugin</artifactId>
   ...
-  
-    false
-  
-
-------------
-
+  <configuration>
+    <skip>false</skip>
+  </configuration>
+</plugin>
+

Background-information for this design-decission can be found on the extra - page {{{./skip.html}To skip or not to skip: that is the question}}... + page To skip or not to skip: that is the question... +

+ + diff --git a/src/site/xhtml/skip.xhtml b/src/site/xhtml/skip.xhtml new file mode 100644 index 00000000..51a20af7 --- /dev/null +++ b/src/site/xhtml/skip.xhtml @@ -0,0 +1,59 @@ + + + + + + +

+ In most use-cases, the hibernate4-maven-plugin is used to create a + test-database automatically. In this use-cases, it is very likely, that it + will result in mistakes/errors, if the goal is executed, when the tests + are skipped. + For example, one might manually overwrite the database-url with the url of + the production-database, in order to run other tests, like starting a + local webserver with the + jetty-maven-plugin. + If the export-goal would be executed in such a scenario, it might erase the + hole production-database, which is not very desireable. +

+

+ Because of this, the configuration-parameter skip defaults to the value + of the proptery maven.test.skip. This way, the execution of the + hibernate4-maven-plugin is skipped automatically, when the tests are + skipped. Think of it as a build-in security-belt. +

+

+ If you do not like that, because you need the plugin to always execute the + export-goal, even if the tests are skipped you can configure that explicitly, + by setting the configuration-parameter skip to false: +

+
+<plugin>
+  <groupId>de.juplo</groupId>
+  <artifactId>hibernate4-maven-plugin</artifactId>
+  ...
+  <configuration>
+    <skip>false</skip>
+  </configuration>
+</plugin>
+

+ Or, if you want the export-goal to be executed by default and to be skipped + if you say so, you can bind the value of the configuration-parameter + skip to a custom property. For example: +

+
+<plugin>
+  <groupId>de.juplo</groupId>
+  <artifactId>hibernate4-maven-plugin</artifactId>
+  ...
+  <configuration>
+    <skip>${foo.bar}</skip>
+  </configuration>
+</plugin>
+

+ This way, the export-goal would be skipped, if you set the property + foo.bar to true. For example, if you specify -Dfoo.bar=true + on the command-line. +

+ + -- 2.20.1 From 856dd31c9b90708e841163c91261a865f9efd224 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Mon, 2 Jun 2014 10:12:24 +0200 Subject: [PATCH 04/16] Updated documentation --- src/site/xhtml/configuration.xhtml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/site/xhtml/configuration.xhtml b/src/site/xhtml/configuration.xhtml index bfaf6fec..e3ce8bcf 100644 --- a/src/site/xhtml/configuration.xhtml +++ b/src/site/xhtml/configuration.xhtml @@ -33,13 +33,14 @@ But be aware, that in this case the database-url, that is build in the application is the same that is used while testing, where the database is droped and recreated by the plugin. + Because of that, - So, you should never fire up this configuration on your production + you should never fire up this configuration on your production system, or your database might be erased!

- Hence, you should specify a different url for testing like in the + A better approach is, to specify a different url for testing like in the following snippet:

@@ -190,7 +191,7 @@
   other configuration-method.
   

- If you realy need to overwrite plugin-configuration-values with + If you need to overwrite plugin-configuration-values with maven-properties, you can use maven-properties in the plugin-configuration:

-- 
2.20.1


From f3dabc0e6e3676244986b5bbffdb67d427c8383c Mon Sep 17 00:00:00 2001
From: Kai Moritz 
Date: Mon, 2 Jun 2014 10:31:12 +0200
Subject: [PATCH 05/16] [maven-release-plugin] prepare release
 hibernate4-maven-plugin-1.0.4

---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index a2abed65..b24e83cf 100644
--- a/pom.xml
+++ b/pom.xml
@@ -13,7 +13,7 @@
   hibernate4-maven-plugin
   Hibernate 4 Maven Plugin
   Plugin for generating a database-schema from Hibernate-4-Mapping-Annotations
-  1.0.4-SNAPSHOT
+  1.0.4
   maven-plugin
   http://juplo.de/hibernate4-maven-plugin
 
-- 
2.20.1


From 3dd832edbd50b1499ea6d53e4bcd0ad4c79640ed Mon Sep 17 00:00:00 2001
From: Kai Moritz 
Date: Mon, 2 Jun 2014 10:31:13 +0200
Subject: [PATCH 06/16] [maven-release-plugin] prepare for next development
 iteration

---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index b24e83cf..df20ab05 100644
--- a/pom.xml
+++ b/pom.xml
@@ -13,7 +13,7 @@
   hibernate4-maven-plugin
   Hibernate 4 Maven Plugin
   Plugin for generating a database-schema from Hibernate-4-Mapping-Annotations
-  1.0.4
+  1.0.5-SNAPSHOT
   maven-plugin
   http://juplo.de/hibernate4-maven-plugin
 
-- 
2.20.1


From 3a3aeaabdb1841faf5e1bf8d220230597fb22931 Mon Sep 17 00:00:00 2001
From: Kai Moritz 
Date: Sat, 25 Oct 2014 16:52:34 +0200
Subject: [PATCH 07/16] Integrated integration test provided by Claus Graf
 (clausgraf@gmail.com)

---
 pom.xml                                       |  4 +
 src/it/dependency-test/dependent/pom.xml      | 26 ++++++
 .../main/java/dependent/DependentEntity.java  | 17 ++++
 src/it/dependency-test/h4mp/pom.xml           | 85 +++++++++++++++++++
 .../h4mp/src/main/java/h4mp/MainEntity.java   | 21 +++++
 .../main/resources/META-INF/persistence.xml   | 17 ++++
 .../src/test/java/h4mp/MainEntityTest.java    | 49 +++++++++++
 .../test/resources/META-INF/persistence.xml   | 23 +++++
 src/it/dependency-test/pom.xml                | 13 +++
 9 files changed, 255 insertions(+)
 create mode 100644 src/it/dependency-test/dependent/pom.xml
 create mode 100644 src/it/dependency-test/dependent/src/main/java/dependent/DependentEntity.java
 create mode 100644 src/it/dependency-test/h4mp/pom.xml
 create mode 100644 src/it/dependency-test/h4mp/src/main/java/h4mp/MainEntity.java
 create mode 100644 src/it/dependency-test/h4mp/src/main/resources/META-INF/persistence.xml
 create mode 100644 src/it/dependency-test/h4mp/src/test/java/h4mp/MainEntityTest.java
 create mode 100644 src/it/dependency-test/h4mp/src/test/resources/META-INF/persistence.xml
 create mode 100644 src/it/dependency-test/pom.xml

diff --git a/pom.xml b/pom.xml
index df20ab05..6433f6f1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -85,6 +85,10 @@
       Mark Robinson
       mark@mrobinson.ca
     
+    
+      Claus Graf
+      clausgraf@gmail.com
+    
   
 
   
diff --git a/src/it/dependency-test/dependent/pom.xml b/src/it/dependency-test/dependent/pom.xml
new file mode 100644
index 00000000..e7c15f39
--- /dev/null
+++ b/src/it/dependency-test/dependent/pom.xml
@@ -0,0 +1,26 @@
+
+	4.0.0
+	de.cege
+	dependent
+	0.0.1
+
+	
+		
+			javax
+			javaee-api
+			7.0
+			provided
+		
+		
+			org.hibernate
+			hibernate-envers
+			4.3.5.Final
+		
+	
+	
+		1.7
+		1.7
+		false
+	
+
\ No newline at end of file
diff --git a/src/it/dependency-test/dependent/src/main/java/dependent/DependentEntity.java b/src/it/dependency-test/dependent/src/main/java/dependent/DependentEntity.java
new file mode 100644
index 00000000..16bc4044
--- /dev/null
+++ b/src/it/dependency-test/dependent/src/main/java/dependent/DependentEntity.java
@@ -0,0 +1,17 @@
+package dependent;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+import org.hibernate.envers.Audited;
+
+@Entity
+@Audited
+public class DependentEntity {
+	@Id
+	@GeneratedValue
+	long id;
+
+	String name;
+}
diff --git a/src/it/dependency-test/h4mp/pom.xml b/src/it/dependency-test/h4mp/pom.xml
new file mode 100644
index 00000000..4e179d25
--- /dev/null
+++ b/src/it/dependency-test/h4mp/pom.xml
@@ -0,0 +1,85 @@
+
+	4.0.0
+	de.cege
+	h4mp
+	0.0.1-SNAPSHOT
+	war
+	h4mp
+
+	
+		
+			javax
+			javaee-api
+			7.0
+			provided
+		
+		
+			org.hibernate
+			hibernate-envers
+			4.3.5.Final
+		
+
+		
+			junit
+			junit
+			4.8.2
+			test
+		
+		
+			org.apache.derby
+			derby
+			10.10.1.1
+			test
+		
+		
+			org.hibernate
+			hibernate-entitymanager
+			4.3.5.Final
+			test
+		
+		
+			org.slf4j
+			slf4j-simple
+			1.5.8
+			test
+		
+
+		
+			de.cege
+			dependent
+			0.0.1
+		
+	
+	
+		1.7
+		1.7
+		false
+	
+
+	
+		
+			
+				de.juplo
+				hibernate4-maven-plugin
+				@project.version@
+				
+					
+						
+							export
+						
+					
+				
+				
+					NONE
+					true
+					true
+					;
+					true
+					CREATE
+					org.hibernate.dialect.PostgreSQL9Dialect
+				
+			
+		
+	
+
diff --git a/src/it/dependency-test/h4mp/src/main/java/h4mp/MainEntity.java b/src/it/dependency-test/h4mp/src/main/java/h4mp/MainEntity.java
new file mode 100644
index 00000000..f717d175
--- /dev/null
+++ b/src/it/dependency-test/h4mp/src/main/java/h4mp/MainEntity.java
@@ -0,0 +1,21 @@
+package h4mp;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+
+import org.hibernate.envers.Audited;
+
+import dependent.DependentEntity;
+
+@Entity
+@Audited
+public class MainEntity {
+	@Id
+	@GeneratedValue
+	long id;
+
+	@ManyToOne
+	DependentEntity dependentEntity;
+}
diff --git a/src/it/dependency-test/h4mp/src/main/resources/META-INF/persistence.xml b/src/it/dependency-test/h4mp/src/main/resources/META-INF/persistence.xml
new file mode 100644
index 00000000..a419eda9
--- /dev/null
+++ b/src/it/dependency-test/h4mp/src/main/resources/META-INF/persistence.xml
@@ -0,0 +1,17 @@
+
+
+	
+		java:jboss/datasources/PostgreSQLDS
+
+		dependent.DependentEntity
+
+		
+			
+			
+		
+	
+
diff --git a/src/it/dependency-test/h4mp/src/test/java/h4mp/MainEntityTest.java b/src/it/dependency-test/h4mp/src/test/java/h4mp/MainEntityTest.java
new file mode 100644
index 00000000..32e528fe
--- /dev/null
+++ b/src/it/dependency-test/h4mp/src/test/java/h4mp/MainEntityTest.java
@@ -0,0 +1,49 @@
+package h4mp;
+
+import static org.junit.Assert.*;
+import static org.hamcrest.core.Is.*;
+
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityTransaction;
+import javax.persistence.Persistence;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import dependent.DependentEntity;
+
+public class MainEntityTest {
+
+	private EntityManager em;
+	private EntityTransaction transaction;
+
+	@Before
+	public void initializeDependencies() {
+		em = Persistence.createEntityManagerFactory("jpaIntegrationTest")
+				.createEntityManager();
+		transaction = em.getTransaction();
+	}
+
+	@SuppressWarnings({ "rawtypes" })
+	@Test
+	public void test() {
+		DependentEntity entity = new DependentEntity();
+
+		transaction.begin();
+		em.persist(entity);
+		transaction.commit();
+
+		List resultList = em.createNativeQuery(
+				"select * from dependententity_aud").getResultList();
+		assertThat(resultList.size(), is(1));
+	}
+
+	@After
+	public void after() {
+		em.close();
+	}
+
+}
diff --git a/src/it/dependency-test/h4mp/src/test/resources/META-INF/persistence.xml b/src/it/dependency-test/h4mp/src/test/resources/META-INF/persistence.xml
new file mode 100644
index 00000000..83e13de6
--- /dev/null
+++ b/src/it/dependency-test/h4mp/src/test/resources/META-INF/persistence.xml
@@ -0,0 +1,23 @@
+
+
+	
+
+		dependent.DependentEntity
+		h4mp.MainEntity
+		
+
+		
+			
+			
+			
+			
+			
+		
+	
+
+
diff --git a/src/it/dependency-test/pom.xml b/src/it/dependency-test/pom.xml
new file mode 100644
index 00000000..8e1506ed
--- /dev/null
+++ b/src/it/dependency-test/pom.xml
@@ -0,0 +1,13 @@
+
+
+  4.0.0
+  de.juplo
+  dependency-test
+  Hibernate 4 Dependency-Test
+  0.1-SNAPSHOT
+  pom
+  
+    dependent
+    h4mp
+  
+
-- 
2.20.1


From 426d18e689b89f33bf71601becfa465a00067b10 Mon Sep 17 00:00:00 2001
From: Kai Moritz 
Date: Sat, 25 Oct 2014 17:29:41 +0200
Subject: [PATCH 08/16] Added patch by Joachim Van der Auwera to support
 package level annotations

---
 pom.xml                                       |   4 +
 .../resources/spring-persistence-context.xml  |   1 +
 src/it/schemaexport-example/schema.sql        |   1 +
 .../schemaexport-example-domain/pom.xml       |   4 +
 .../test/schemaexport/domain/Department.java  |   4 +
 .../schemaexport/domain/EnumUserType.java     | 110 ++++++
 .../de/test/schemaexport/domain/Gender.java   |  23 ++
 .../schemaexport/domain/package-info.java     |  13 +
 .../main/resources/META-INF/persistence.xml   |   1 +
 .../juplo/plugins/hibernate4/Hbm2DdlMojo.java | 315 +++++++++---------
 .../hibernate4/ValidationConfiguration.java   |   5 +
 11 files changed, 328 insertions(+), 153 deletions(-)
 create mode 100644 src/it/schemaexport-example/schemaexport-example-domain/src/main/java/de/test/schemaexport/domain/EnumUserType.java
 create mode 100644 src/it/schemaexport-example/schemaexport-example-domain/src/main/java/de/test/schemaexport/domain/Gender.java
 create mode 100644 src/it/schemaexport-example/schemaexport-example-domain/src/main/java/de/test/schemaexport/domain/package-info.java

diff --git a/pom.xml b/pom.xml
index 6433f6f1..272a1ea5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -89,6 +89,10 @@
       Claus Graf
       clausgraf@gmail.com
     
+    
+      Joachim Van der Auwera
+      joachim@progs.be
+    
   
 
   
diff --git a/src/it/hibernate4-maven-plugin-envers-sample/src/main/resources/spring-persistence-context.xml b/src/it/hibernate4-maven-plugin-envers-sample/src/main/resources/spring-persistence-context.xml
index 78f81117..0cff8cc6 100644
--- a/src/it/hibernate4-maven-plugin-envers-sample/src/main/resources/spring-persistence-context.xml
+++ b/src/it/hibernate4-maven-plugin-envers-sample/src/main/resources/spring-persistence-context.xml
@@ -24,6 +24,7 @@
           p:persistenceUnitName="${jpa.persistence.context.name}"
           p:persistenceXmlLocation="classpath:META-INF/persistence-jpa.xml"
           p:dataSource-ref="dataSource"
+          p:packagesToScan="de.test.schemaexport.domain"
             >
 
         
diff --git a/src/it/schemaexport-example/schema.sql b/src/it/schemaexport-example/schema.sql
index e8f93bae..bd7142cd 100644
--- a/src/it/schemaexport-example/schema.sql
+++ b/src/it/schemaexport-example/schema.sql
@@ -8,6 +8,7 @@
 
     create table ABTEILUNG (
         OID bigint generated by default as identity (start with 1),
+        gender varchar(255),
         name varchar(255) not null,
         primary key (OID)
     );
diff --git a/src/it/schemaexport-example/schemaexport-example-domain/pom.xml b/src/it/schemaexport-example/schemaexport-example-domain/pom.xml
index c2bc2d8f..43b71b30 100644
--- a/src/it/schemaexport-example/schemaexport-example-domain/pom.xml
+++ b/src/it/schemaexport-example/schemaexport-example-domain/pom.xml
@@ -24,6 +24,10 @@
 			hibernate-validator
 			provided
 		
+		
+			org.hibernate
+			hibernate-core
+		
 	
 	
 
diff --git a/src/it/schemaexport-example/schemaexport-example-domain/src/main/java/de/test/schemaexport/domain/Department.java b/src/it/schemaexport-example/schemaexport-example-domain/src/main/java/de/test/schemaexport/domain/Department.java
index b523659c..64ff1332 100644
--- a/src/it/schemaexport-example/schemaexport-example-domain/src/main/java/de/test/schemaexport/domain/Department.java
+++ b/src/it/schemaexport-example/schemaexport-example-domain/src/main/java/de/test/schemaexport/domain/Department.java
@@ -6,6 +6,7 @@ import javax.persistence.GeneratedValue;
 import javax.persistence.GenerationType;
 import javax.persistence.Id;
 import javax.persistence.Table;
+import org.hibernate.annotations.Type;
 
 /**
  * Abteilungsklasse (Generator-Beispielcode).
@@ -25,6 +26,9 @@ public class Department {
 	@Column(name = "name", nullable = false)
 	private String name;
 
+	@Type(type = "genderType")
+	private Gender gender;
+
 	public long getOid() {
 		return oid;
 	}
diff --git a/src/it/schemaexport-example/schemaexport-example-domain/src/main/java/de/test/schemaexport/domain/EnumUserType.java b/src/it/schemaexport-example/schemaexport-example-domain/src/main/java/de/test/schemaexport/domain/EnumUserType.java
new file mode 100644
index 00000000..6e598908
--- /dev/null
+++ b/src/it/schemaexport-example/schemaexport-example-domain/src/main/java/de/test/schemaexport/domain/EnumUserType.java
@@ -0,0 +1,110 @@
+package de.test.schemaexport.domain;
+
+import org.hibernate.HibernateException;
+import org.hibernate.engine.spi.SessionImplementor;
+import org.hibernate.usertype.EnhancedUserType;
+import org.hibernate.usertype.ParameterizedType;
+
+import java.io.Serializable;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Types;
+import java.util.Properties;
+
+/**
+ * This Hibernate UserType is used to map JDK 5 Enums directly in a column.
+ * Define this UserType in your hbm.xml mapping file like the following example:
+ */
+public class EnumUserType implements EnhancedUserType, ParameterizedType {
+
+    private Class enumClass;
+
+    @Override
+    public void setParameterValues(Properties parameters) {
+        String enumClassName = parameters.getProperty("enumClassName");
+        try {
+            enumClass = (Class) Class.forName(enumClassName);
+        } catch (ClassNotFoundException cnfe) {
+            throw new HibernateException("Enum class not found", cnfe);
+        }
+    }
+
+    @Override
+    public Object assemble(Serializable cached, Object owner) throws HibernateException {
+        return cached;
+    }
+
+    @Override
+    public Object deepCopy(Object value) throws HibernateException {
+        return value;
+    }
+
+    @Override
+    public Serializable disassemble(Object value) throws HibernateException {
+        return (Enum) value;
+    }
+
+    @Override
+    public boolean equals(Object x, Object y) throws HibernateException {
+        return x == y;
+    }
+
+    @Override
+    public int hashCode(Object x) throws HibernateException {
+        return x.hashCode();
+    }
+
+    @Override
+    public boolean isMutable() {
+        return false;
+    }
+
+    @Override
+    public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor sessionImplementor, Object owner)
+            throws HibernateException, SQLException {
+        String name = rs.getString(names[0]);
+        return rs.wasNull() ? null : Enum.valueOf(enumClass, name);
+    }
+
+    @Override
+    public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor sessionImplementor)
+            throws HibernateException, SQLException {
+        if (value == null) {
+            st.setNull(index, Types.VARCHAR);
+        } else {
+            st.setString(index, ((Enum) value).name());
+        }
+    }
+
+    @Override
+    public Object replace(Object original, Object target, Object owner) throws HibernateException {
+        return original;
+    }
+
+    @Override
+    public Class returnedClass() {
+        return enumClass;
+    }
+
+    @Override
+    public int[] sqlTypes() {
+        return new int[]{Types.VARCHAR};
+    }
+
+    @Override
+    public Object fromXMLString(String xmlValue) {
+        return Enum.valueOf(enumClass, xmlValue);
+    }
+
+    @Override
+    public String objectToSQLString(Object value) {
+        return '\'' + ((Enum) value).name() + '\'';
+    }
+
+    @Override
+    public String toXMLString(Object value) {
+        return ((Enum) value).name();
+    }
+
+}
diff --git a/src/it/schemaexport-example/schemaexport-example-domain/src/main/java/de/test/schemaexport/domain/Gender.java b/src/it/schemaexport-example/schemaexport-example-domain/src/main/java/de/test/schemaexport/domain/Gender.java
new file mode 100644
index 00000000..dca1d000
--- /dev/null
+++ b/src/it/schemaexport-example/schemaexport-example-domain/src/main/java/de/test/schemaexport/domain/Gender.java
@@ -0,0 +1,23 @@
+package de.test.schemaexport.domain;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+/**
+ * Abteilungsklasse (Generator-Beispielcode).
+ * 
+ * copyright
+ *
+ */
+public enum Gender {
+
+	MALE,
+    FEMALE,
+    UNKNOWN,
+    OTHER
+	
+}
diff --git a/src/it/schemaexport-example/schemaexport-example-domain/src/main/java/de/test/schemaexport/domain/package-info.java b/src/it/schemaexport-example/schemaexport-example-domain/src/main/java/de/test/schemaexport/domain/package-info.java
new file mode 100644
index 00000000..d1491c6d
--- /dev/null
+++ b/src/it/schemaexport-example/schemaexport-example-domain/src/main/java/de/test/schemaexport/domain/package-info.java
@@ -0,0 +1,13 @@
+@TypeDefs({
+        @TypeDef(name = "genderType",
+                defaultForType = Gender.class,
+                typeClass = EnumUserType.class,
+                parameters = @Parameter(name = "enumClassName",
+                        value = "de.test.schemaexport.domain.Gender"))
+})
+package de.test.schemaexport.domain;
+
+import de.test.schemaexport.domain.EnumUserType;
+import org.hibernate.annotations.Parameter;
+import org.hibernate.annotations.TypeDef;
+import org.hibernate.annotations.TypeDefs;
\ No newline at end of file
diff --git a/src/it/schemaexport-example/schemaexport-example-persistence-impl/src/main/resources/META-INF/persistence.xml b/src/it/schemaexport-example/schemaexport-example-persistence-impl/src/main/resources/META-INF/persistence.xml
index 75784726..0eaf2d3a 100644
--- a/src/it/schemaexport-example/schemaexport-example-persistence-impl/src/main/resources/META-INF/persistence.xml
+++ b/src/it/schemaexport-example/schemaexport-example-persistence-impl/src/main/resources/META-INF/persistence.xml
@@ -3,6 +3,7 @@
 	xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
 	
 		
+		de.test.schemaexport.domain
 		de.test.schemaexport.domain.Department
 		de.test.schemaexport.domain.Employee
 		
diff --git a/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java b/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java
index f73fa2b5..73f0ab06 100644
--- a/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java
+++ b/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java
@@ -58,7 +58,6 @@ import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.project.MavenProject;
-import org.hibernate.cfg.Configuration;
 import org.hibernate.cfg.NamingStrategy;
 import org.hibernate.envers.configuration.spi.AuditConfiguration;
 import org.hibernate.tool.hbm2ddl.SchemaExport;
@@ -670,7 +669,7 @@ public class Hbm2DdlMojo extends AbstractMojo
       throw new MojoFailureException("Hibernate configuration is missing!");
     }
 
-    final Configuration config = new ValidationConfiguration(hibernateDialect);
+    final ValidationConfiguration config = new ValidationConfiguration(hibernateDialect);
 
     config.setProperties(properties);
 
@@ -691,181 +690,191 @@ public class Hbm2DdlMojo extends AbstractMojo
       }
     }
 
-    getLog().debug("Adding annotated classes to hibernate-mapping-configuration...");
-    for (Class annotatedClass : classes)
+    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
+    Connection connection = null;
+    MavenLogAppender.startPluginLog(this);
+    try
     {
-      getLog().debug("Class " + annotatedClass);
-      config.addAnnotatedClass(annotatedClass);
-    }
+      /**
+       * Change class-loader of current thread, so that hibernate can
+       * see all dependencies!
+       */
+      Thread.currentThread().setContextClassLoader(classLoader);
 
-    if (hibernateMapping != null)
-    {
-      try
+      getLog().debug("Adding annotated classes to hibernate-mapping-configuration...");
+      // build annotated packages
+      Set packages = new HashSet();
+      for (Class annotatedClass : classes)
       {
-        MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
-        for (String filename : hibernateMapping.split("[\\s,]+"))
+        String packageName = annotatedClass.getPackage().getName();
+        if (!packages.contains(packageName))
         {
-          // First try the filename as absolute/relative path
-          File file = new File(filename);
-          if (!file.exists())
+          getLog().debug("Add package " + packageName);
+          packages.add(packageName);
+          config.addPackage(packageName);
+          getLog().debug("type definintions" + config.getTypeDefs());
+        }
+        getLog().debug("Class " + annotatedClass);
+        config.addAnnotatedClass(annotatedClass);
+      }
+
+      if (hibernateMapping != null)
+      {
+        try
+        {
+          MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
+          for (String filename : hibernateMapping.split("[\\s,]+"))
           {
-            // If the file was not found, search for it in the resource-directories
-            for (Resource resource : project.getResources())
+            // First try the filename as absolute/relative path
+            File file = new File(filename);
+            if (!file.exists())
             {
-              file = new File(resource.getDirectory() + File.separator + filename);
-              if (file.exists())
-                break;
+              // If the file was not found, search for it in the resource-directories
+              for (Resource resource : project.getResources())
+              {
+                file = new File(resource.getDirectory() + File.separator + filename);
+                if (file.exists())
+                  break;
+              }
             }
-          }
-          if (file != null && file.exists())
-          {
-            InputStream is = new FileInputStream(file);
-            byte[] buffer = new byte[1024*4]; // copy data in 4MB-chunks
-            int i;
-            while((i = is.read(buffer)) > -1)
-              digest.update(buffer, 0, i);
-            is.close();
-            byte[] bytes = digest.digest();
-            BigInteger bi = new BigInteger(1, bytes);
-            String newMd5 = String.format("%0" + (bytes.length << 1) + "x", bi);
-            String oldMd5 = !md5s.containsKey(filename) ? "" : md5s.get(filename);
-            if (!newMd5.equals(oldMd5))
+            if (file != null && file.exists())
             {
-              getLog().debug("Found new or modified mapping-file: " + filename);
-              modified = true;
-              md5s.put(filename, newMd5);
+              InputStream is = new FileInputStream(file);
+              byte[] buffer = new byte[1024*4]; // copy data in 4MB-chunks
+              int i;
+              while((i = is.read(buffer)) > -1)
+                digest.update(buffer, 0, i);
+              is.close();
+              byte[] bytes = digest.digest();
+              BigInteger bi = new BigInteger(1, bytes);
+              String newMd5 = String.format("%0" + (bytes.length << 1) + "x", bi);
+              String oldMd5 = !md5s.containsKey(filename) ? "" : md5s.get(filename);
+              if (!newMd5.equals(oldMd5))
+              {
+                getLog().debug("Found new or modified mapping-file: " + filename);
+                modified = true;
+                md5s.put(filename, newMd5);
+              }
+              else
+              {
+                getLog().debug(oldMd5 + " -> mapping-file unchanged: " + filename);
+              }
+              getLog().debug("Adding mappings from XML-configurationfile: " + file);
+              config.addFile(file);
             }
             else
-            {
-              getLog().debug(oldMd5 + " -> mapping-file unchanged: " + filename);
-            }
-            getLog().debug("Adding mappings from XML-configurationfile: " + file);
-            config.addFile(file);
+              throw new MojoFailureException("File " + filename + " could not be found in any of the configured resource-directories!");
           }
-          else
-            throw new MojoFailureException("File " + filename + " could not be found in any of the configured resource-directories!");
+        }
+        catch (NoSuchAlgorithmException e)
+        {
+          throw new MojoFailureException("Cannot calculate MD5 sums!", e);
+        }
+        catch (FileNotFoundException e)
+        {
+          throw new MojoFailureException("Cannot calculate MD5 sums!", e);
+        }
+        catch (IOException e)
+        {
+          throw new MojoFailureException("Cannot calculate MD5 sums!", e);
         }
       }
-      catch (NoSuchAlgorithmException e)
+
+      Target target = null;
+      try
       {
-        throw new MojoFailureException("Cannot calculate MD5 sums!", e);
+        target = Target.valueOf(this.target.toUpperCase());
       }
-      catch (FileNotFoundException e)
+      catch (IllegalArgumentException e)
       {
-        throw new MojoFailureException("Cannot calculate MD5 sums!", e);
+        getLog().error("Invalid value for configuration-option \"target\": " + this.target);
+        getLog().error("Valid values are: NONE, SCRIPT, EXPORT, BOTH");
+        throw new MojoExecutionException("Invalid value for configuration-option \"target\"");
       }
-      catch (IOException e)
+      Type type = null;
+      try
       {
-        throw new MojoFailureException("Cannot calculate MD5 sums!", e);
+        type = Type.valueOf(this.type.toUpperCase());
+      }
+      catch (IllegalArgumentException e)
+      {
+        getLog().error("Invalid value for configuration-option \"type\": " + this.type);
+        getLog().error("Valid values are: NONE, CREATE, DROP, BOTH");
+        throw new MojoExecutionException("Invalid value for configuration-option \"type\"");
       }
-    }
-
-    Target target = null;
-    try
-    {
-      target = Target.valueOf(this.target.toUpperCase());
-    }
-    catch (IllegalArgumentException e)
-    {
-      getLog().error("Invalid value for configuration-option \"target\": " + this.target);
-      getLog().error("Valid values are: NONE, SCRIPT, EXPORT, BOTH");
-      throw new MojoExecutionException("Invalid value for configuration-option \"target\"");
-    }
-    Type type = null;
-    try
-    {
-      type = Type.valueOf(this.type.toUpperCase());
-    }
-    catch (IllegalArgumentException e)
-    {
-      getLog().error("Invalid value for configuration-option \"type\": " + this.type);
-      getLog().error("Valid values are: NONE, CREATE, DROP, BOTH");
-      throw new MojoExecutionException("Invalid value for configuration-option \"type\"");
-    }
 
-    if (target.equals(Target.SCRIPT) || target.equals(Target.NONE))
-    {
-      project.getProperties().setProperty(EXPORT_SKIPPED_PROPERTY, "true");
-    }
-    if (
-        !modified
-        && !target.equals(Target.SCRIPT)
-        && !target.equals(Target.NONE)
-        && !force
-      )
-    {
-      getLog().info("No modified annotated classes or mapping-files found and dialect unchanged.");
-      getLog().info("Skipping schema generation!");
-      project.getProperties().setProperty(EXPORT_SKIPPED_PROPERTY, "true");
-      return;
-    }
+      if (target.equals(Target.SCRIPT) || target.equals(Target.NONE))
+      {
+        project.getProperties().setProperty(EXPORT_SKIPPED_PROPERTY, "true");
+      }
+      if (
+          !modified
+          && !target.equals(Target.SCRIPT)
+          && !target.equals(Target.NONE)
+          && !force
+        )
+      {
+        getLog().info("No modified annotated classes or mapping-files found and dialect unchanged.");
+        getLog().info("Skipping schema generation!");
+        project.getProperties().setProperty(EXPORT_SKIPPED_PROPERTY, "true");
+        return;
+      }
 
-    getLog().info("Gathered hibernate-configuration (turn on debugging for details):");
-    for (Entry entry : properties.entrySet())
-      getLog().info("  " + entry.getKey() + " = " + entry.getValue());
+      getLog().info("Gathered hibernate-configuration (turn on debugging for details):");
+      for (Entry entry : properties.entrySet())
+        getLog().info("  " + entry.getKey() + " = " + entry.getValue());
 
-    Connection connection = null;
-    try
-    {
-      /**
-       * The connection must be established outside of hibernate, because
-       * hibernate does not use the context-classloader of the current
-       * thread and, hence, would not be able to resolve the driver-class!
-       */
-      getLog().debug("Target: " + target + ", Type: " + type);
-      switch (target)
+      try
       {
-        case EXPORT:
-        case BOTH:
-          switch (type)
-          {
-            case CREATE:
-            case DROP:
-            case BOTH:
-              Class driverClass = classLoader.loadClass(properties.getProperty(DRIVER_CLASS));
-              getLog().debug("Registering JDBC-driver " + driverClass.getName());
-              DriverManager.registerDriver(new DriverProxy((Driver)driverClass.newInstance()));
-              getLog().debug(
-                  "Opening JDBC-connection to "
-                  + properties.getProperty(URL)
-                  + " as "
-                  + properties.getProperty(USERNAME)
-                  + " with password "
-                  + properties.getProperty(PASSWORD)
-                  );
-              connection = DriverManager.getConnection(
-                  properties.getProperty(URL),
-                  properties.getProperty(USERNAME),
-                  properties.getProperty(PASSWORD)
-                  );
-          }
+        /**
+         * The connection must be established outside of hibernate, because
+         * hibernate does not use the context-classloader of the current
+         * thread and, hence, would not be able to resolve the driver-class!
+         */
+        getLog().debug("Target: " + target + ", Type: " + type);
+        switch (target)
+        {
+          case EXPORT:
+          case BOTH:
+            switch (type)
+            {
+              case CREATE:
+              case DROP:
+              case BOTH:
+                Class driverClass = classLoader.loadClass(properties.getProperty(DRIVER_CLASS));
+                getLog().debug("Registering JDBC-driver " + driverClass.getName());
+                DriverManager.registerDriver(new DriverProxy((Driver)driverClass.newInstance()));
+                getLog().debug(
+                    "Opening JDBC-connection to "
+                    + properties.getProperty(URL)
+                    + " as "
+                    + properties.getProperty(USERNAME)
+                    + " with password "
+                    + properties.getProperty(PASSWORD)
+                    );
+                connection = DriverManager.getConnection(
+                    properties.getProperty(URL),
+                    properties.getProperty(USERNAME),
+                    properties.getProperty(PASSWORD)
+                    );
+            }
+        }
+      }
+      catch (ClassNotFoundException e)
+      {
+        getLog().error("Dependency for driver-class " + properties.getProperty(DRIVER_CLASS) + " is missing!");
+        throw new MojoExecutionException(e.getMessage());
+      }
+      catch (Exception e)
+      {
+        getLog().error("Cannot establish connection to database!");
+        Enumeration drivers = DriverManager.getDrivers();
+        if (!drivers.hasMoreElements())
+          getLog().error("No drivers registered!");
+        while (drivers.hasMoreElements())
+          getLog().debug("Driver: " + drivers.nextElement());
+        throw new MojoExecutionException(e.getMessage());
       }
-    }
-    catch (ClassNotFoundException e)
-    {
-      getLog().error("Dependency for driver-class " + properties.getProperty(DRIVER_CLASS) + " is missing!");
-      throw new MojoExecutionException(e.getMessage());
-    }
-    catch (Exception e)
-    {
-      getLog().error("Cannot establish connection to database!");
-      Enumeration drivers = DriverManager.getDrivers();
-      if (!drivers.hasMoreElements())
-        getLog().error("No drivers registered!");
-      while (drivers.hasMoreElements())
-        getLog().debug("Driver: " + drivers.nextElement());
-      throw new MojoExecutionException(e.getMessage());
-    }
-
-    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
-    MavenLogAppender.startPluginLog(this);
-    try
-    {
-      /**
-       * Change class-loader of current thread, so that hibernate can
-       * see all dependencies!
-       */
-      Thread.currentThread().setContextClassLoader(classLoader);
 
       config.buildMappings();
 
diff --git a/src/main/java/de/juplo/plugins/hibernate4/ValidationConfiguration.java b/src/main/java/de/juplo/plugins/hibernate4/ValidationConfiguration.java
index 6748ba5e..99ff1374 100644
--- a/src/main/java/de/juplo/plugins/hibernate4/ValidationConfiguration.java
+++ b/src/main/java/de/juplo/plugins/hibernate4/ValidationConfiguration.java
@@ -56,4 +56,9 @@ public class ValidationConfiguration extends Configuration
       throw new RuntimeException(e);
     }
   }
+
+  public String getTypeDefs()
+  {
+    return typeDefs.entrySet().toString();
+  }
 }
-- 
2.20.1


From d27f7af23c82167e873ce143e50ce9d9a65f5e61 Mon Sep 17 00:00:00 2001
From: Kai Moritz 
Date: Sun, 26 Oct 2014 11:16:00 +0100
Subject: [PATCH 09/16] Renamed an integration-test to test for whitespaces in
 the filename

---
 src/it/{dependency-test => dependency test}/dependent/pom.xml     | 0
 .../dependent/src/main/java/dependent/DependentEntity.java        | 0
 src/it/{dependency-test => dependency test}/h4mp/pom.xml          | 0
 .../h4mp/src/main/java/h4mp/MainEntity.java                       | 0
 .../h4mp/src/main/resources/META-INF/persistence.xml              | 0
 .../h4mp/src/test/java/h4mp/MainEntityTest.java                   | 0
 .../h4mp/src/test/resources/META-INF/persistence.xml              | 0
 src/it/{dependency-test => dependency test}/pom.xml               | 0
 8 files changed, 0 insertions(+), 0 deletions(-)
 rename src/it/{dependency-test => dependency test}/dependent/pom.xml (100%)
 rename src/it/{dependency-test => dependency test}/dependent/src/main/java/dependent/DependentEntity.java (100%)
 rename src/it/{dependency-test => dependency test}/h4mp/pom.xml (100%)
 rename src/it/{dependency-test => dependency test}/h4mp/src/main/java/h4mp/MainEntity.java (100%)
 rename src/it/{dependency-test => dependency test}/h4mp/src/main/resources/META-INF/persistence.xml (100%)
 rename src/it/{dependency-test => dependency test}/h4mp/src/test/java/h4mp/MainEntityTest.java (100%)
 rename src/it/{dependency-test => dependency test}/h4mp/src/test/resources/META-INF/persistence.xml (100%)
 rename src/it/{dependency-test => dependency test}/pom.xml (100%)

diff --git a/src/it/dependency-test/dependent/pom.xml b/src/it/dependency test/dependent/pom.xml
similarity index 100%
rename from src/it/dependency-test/dependent/pom.xml
rename to src/it/dependency test/dependent/pom.xml
diff --git a/src/it/dependency-test/dependent/src/main/java/dependent/DependentEntity.java b/src/it/dependency test/dependent/src/main/java/dependent/DependentEntity.java
similarity index 100%
rename from src/it/dependency-test/dependent/src/main/java/dependent/DependentEntity.java
rename to src/it/dependency test/dependent/src/main/java/dependent/DependentEntity.java
diff --git a/src/it/dependency-test/h4mp/pom.xml b/src/it/dependency test/h4mp/pom.xml
similarity index 100%
rename from src/it/dependency-test/h4mp/pom.xml
rename to src/it/dependency test/h4mp/pom.xml
diff --git a/src/it/dependency-test/h4mp/src/main/java/h4mp/MainEntity.java b/src/it/dependency test/h4mp/src/main/java/h4mp/MainEntity.java
similarity index 100%
rename from src/it/dependency-test/h4mp/src/main/java/h4mp/MainEntity.java
rename to src/it/dependency test/h4mp/src/main/java/h4mp/MainEntity.java
diff --git a/src/it/dependency-test/h4mp/src/main/resources/META-INF/persistence.xml b/src/it/dependency test/h4mp/src/main/resources/META-INF/persistence.xml
similarity index 100%
rename from src/it/dependency-test/h4mp/src/main/resources/META-INF/persistence.xml
rename to src/it/dependency test/h4mp/src/main/resources/META-INF/persistence.xml
diff --git a/src/it/dependency-test/h4mp/src/test/java/h4mp/MainEntityTest.java b/src/it/dependency test/h4mp/src/test/java/h4mp/MainEntityTest.java
similarity index 100%
rename from src/it/dependency-test/h4mp/src/test/java/h4mp/MainEntityTest.java
rename to src/it/dependency test/h4mp/src/test/java/h4mp/MainEntityTest.java
diff --git a/src/it/dependency-test/h4mp/src/test/resources/META-INF/persistence.xml b/src/it/dependency test/h4mp/src/test/resources/META-INF/persistence.xml
similarity index 100%
rename from src/it/dependency-test/h4mp/src/test/resources/META-INF/persistence.xml
rename to src/it/dependency test/h4mp/src/test/resources/META-INF/persistence.xml
diff --git a/src/it/dependency-test/pom.xml b/src/it/dependency test/pom.xml
similarity index 100%
rename from src/it/dependency-test/pom.xml
rename to src/it/dependency test/pom.xml
-- 
2.20.1


From 74c0dd783b84c90e116f3e7f1c8d6109845ba71f Mon Sep 17 00:00:00 2001
From: Kai Moritz 
Date: Mon, 27 Oct 2014 09:04:48 +0100
Subject: [PATCH 10/16] Fixed NullPointerException, when dialect is specified
 in properties-file

Also added an integration test-case, that proofed, that the error was
solved.
---
 src/it/properties/h2.sql                      | 12 +++++
 src/it/properties/pom.xml                     | 53 +++++++++++++++++++
 .../tests/SimplestMavenHib4Test.java          | 32 +++++++++++
 .../src/main/resources/hibernate.properties   |  1 +
 src/it/properties/verify.bsh                  |  7 +++
 .../juplo/plugins/hibernate4/Hbm2DdlMojo.java |  4 ++
 6 files changed, 109 insertions(+)
 create mode 100644 src/it/properties/h2.sql
 create mode 100644 src/it/properties/pom.xml
 create mode 100644 src/it/properties/src/main/java/de/juplo/plugins/hibernate4/tests/SimplestMavenHib4Test.java
 create mode 100644 src/it/properties/src/main/resources/hibernate.properties
 create mode 100644 src/it/properties/verify.bsh

diff --git a/src/it/properties/h2.sql b/src/it/properties/h2.sql
new file mode 100644
index 00000000..9569fa60
--- /dev/null
+++ b/src/it/properties/h2.sql
@@ -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
index 00000000..f3a6fc73
--- /dev/null
+++ b/src/it/properties/pom.xml
@@ -0,0 +1,53 @@
+
+
+  4.0.0
+  de.juplo
+  hibernate4-properties-test
+  Hibernate 4 Test - Dialect in properties-file
+  0.1-SNAPSHOT
+  jar
+  
+    
+  
+  
+    
+      org.hibernate
+      hibernate-core
+      4.3.0.Final
+    
+  
+  
+    
+      
+        org.apache.maven.plugins
+        maven-compiler-plugin
+        2.0.2
+        
+          1.7
+          1.7
+          utf8
+          true
+        
+      
+      
+      
+        de.juplo
+        hibernate4-maven-plugin
+        @project.version@
+        
+          
+          none
+          
+          both
+        
+        
+          
+            
+              export
+            
+          
+        
+      
+    
+  
+
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
index 00000000..3a3f565b
--- /dev/null
+++ b/src/it/properties/src/main/java/de/juplo/plugins/hibernate4/tests/SimplestMavenHib4Test.java
@@ -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
index 00000000..0db87124
--- /dev/null
+++ b/src/it/properties/src/main/resources/hibernate.properties
@@ -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
index 00000000..0dfcefe5
--- /dev/null
+++ b/src/it/properties/verify.bsh
@@ -0,0 +1,7 @@
+import de.juplo.test.FileComparator;
+
+
+FileComparator comparator = new FileComparator(basedir);
+
+if (!comparator.isEqual("h2.sql","target/schema.sql"))
+  return false;
diff --git a/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java b/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java
index 73f0ab06..fa4ce6a0 100644
--- a/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java
+++ b/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java
@@ -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))
-- 
2.20.1


From 473c3ef285c19e0f0b85643b67bbd77e06c0b926 Mon Sep 17 00:00:00 2001
From: Kai Moritz 
Date: Tue, 28 Oct 2014 23:37:45 +0100
Subject: [PATCH 11/16] Explained how to suppress dependency-scanning in
 documentation

Also added a test-case to be sure, that dependency-scanning is skipped, if
the parameter "dependencyScanning" is set to "none".
---
 src/it/ignored-dependency/ignored/pom.xml     | 22 ++++++++
 .../src/main/java/ignored/IgnoredEntity.java  | 15 ++++++
 src/it/ignored-dependency/main/pom.xml        | 53 +++++++++++++++++++
 .../main/src/main/java/main/MainEntity.java   | 19 +++++++
 .../main/resources/META-INF/persistence.xml   | 17 ++++++
 src/it/ignored-dependency/pom.xml             | 16 ++++++
 src/it/ignored-dependency/schema.sql          |  7 +++
 src/it/ignored-dependency/verify.bsh          |  7 +++
 .../juplo/plugins/hibernate4/Hbm2DdlMojo.java |  3 ++
 src/site/xhtml/pitfalls.xhtml                 | 18 ++++++-
 10 files changed, 176 insertions(+), 1 deletion(-)
 create mode 100644 src/it/ignored-dependency/ignored/pom.xml
 create mode 100644 src/it/ignored-dependency/ignored/src/main/java/ignored/IgnoredEntity.java
 create mode 100644 src/it/ignored-dependency/main/pom.xml
 create mode 100644 src/it/ignored-dependency/main/src/main/java/main/MainEntity.java
 create mode 100644 src/it/ignored-dependency/main/src/main/resources/META-INF/persistence.xml
 create mode 100644 src/it/ignored-dependency/pom.xml
 create mode 100644 src/it/ignored-dependency/schema.sql
 create mode 100644 src/it/ignored-dependency/verify.bsh

diff --git a/src/it/ignored-dependency/ignored/pom.xml b/src/it/ignored-dependency/ignored/pom.xml
new file mode 100644
index 00000000..28e8ab9b
--- /dev/null
+++ b/src/it/ignored-dependency/ignored/pom.xml
@@ -0,0 +1,22 @@
+
+
+
+  4.0.0
+  de.juplo
+  ignored
+  1
+
+  
+    
+      org.hibernate
+      hibernate-core
+      4.3.5.Final
+    
+  
+
+  
+    1.7
+    1.7
+  
+
+
diff --git a/src/it/ignored-dependency/ignored/src/main/java/ignored/IgnoredEntity.java b/src/it/ignored-dependency/ignored/src/main/java/ignored/IgnoredEntity.java
new file mode 100644
index 00000000..afb73c38
--- /dev/null
+++ b/src/it/ignored-dependency/ignored/src/main/java/ignored/IgnoredEntity.java
@@ -0,0 +1,15 @@
+package ignored;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+@Entity
+public class IgnoredEntity
+{
+  @Id
+  @GeneratedValue
+  Long id;
+
+  String name;
+}
diff --git a/src/it/ignored-dependency/main/pom.xml b/src/it/ignored-dependency/main/pom.xml
new file mode 100644
index 00000000..d198fc9b
--- /dev/null
+++ b/src/it/ignored-dependency/main/pom.xml
@@ -0,0 +1,53 @@
+
+
+
+  4.0.0
+  de.juplo
+  main
+  1
+  jar
+  main
+
+  
+    
+      org.hibernate
+      hibernate-core
+      4.3.5.Final
+    
+    
+      de.juplo
+      ignored
+      1
+    
+  
+
+  
+    1.7
+    1.7
+  
+
+  
+    
+      
+        de.juplo
+        hibernate4-maven-plugin
+        @project.version@
+        
+          
+            
+              export
+            
+          
+        
+        
+          NONE
+          true
+          CREATE
+          org.hibernate.dialect.PostgreSQL9Dialect
+          none
+        
+      
+    
+  
+
+
diff --git a/src/it/ignored-dependency/main/src/main/java/main/MainEntity.java b/src/it/ignored-dependency/main/src/main/java/main/MainEntity.java
new file mode 100644
index 00000000..a86f8096
--- /dev/null
+++ b/src/it/ignored-dependency/main/src/main/java/main/MainEntity.java
@@ -0,0 +1,19 @@
+package main;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Transient;
+
+import ignored.IgnoredEntity;
+
+@Entity
+public class MainEntity
+{
+  @Id
+  @GeneratedValue
+  long id;
+
+  @Transient
+  IgnoredEntity ignoredEntity;
+}
diff --git a/src/it/ignored-dependency/main/src/main/resources/META-INF/persistence.xml b/src/it/ignored-dependency/main/src/main/resources/META-INF/persistence.xml
new file mode 100644
index 00000000..a419eda9
--- /dev/null
+++ b/src/it/ignored-dependency/main/src/main/resources/META-INF/persistence.xml
@@ -0,0 +1,17 @@
+
+
+	
+		java:jboss/datasources/PostgreSQLDS
+
+		dependent.DependentEntity
+
+		
+			
+			
+		
+	
+
diff --git a/src/it/ignored-dependency/pom.xml b/src/it/ignored-dependency/pom.xml
new file mode 100644
index 00000000..27dd2990
--- /dev/null
+++ b/src/it/ignored-dependency/pom.xml
@@ -0,0 +1,16 @@
+
+
+
+  4.0.0
+  de.juplo
+  ignored-dependency
+  Hibernate 4 Maven Plugin - Ignored Dependen Test
+  1
+  pom
+
+  
+    ignored
+    main
+  
+
+
diff --git a/src/it/ignored-dependency/schema.sql b/src/it/ignored-dependency/schema.sql
new file mode 100644
index 00000000..510de4f2
--- /dev/null
+++ b/src/it/ignored-dependency/schema.sql
@@ -0,0 +1,7 @@
+
+    create table MainEntity (
+        id int8 not null,
+        primary key (id)
+    );
+
+    create sequence hibernate_sequence;
diff --git a/src/it/ignored-dependency/verify.bsh b/src/it/ignored-dependency/verify.bsh
new file mode 100644
index 00000000..47470ce6
--- /dev/null
+++ b/src/it/ignored-dependency/verify.bsh
@@ -0,0 +1,7 @@
+import de.juplo.test.FileComparator;
+
+
+FileComparator comparator = new FileComparator(basedir);
+
+if (!comparator.isEqual("schema.sql","main/target/schema.sql"))
+  return false;
diff --git a/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java b/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java
index fa4ce6a0..85ae5182 100644
--- a/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java
+++ b/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java
@@ -143,6 +143,9 @@ public class Hbm2DdlMojo extends AbstractMojo
    * scanned for annotated classes. Multiple scopes can be seperated by
    * white space or commas.
    * 

+ * If you do not want any dependencies to be scanned for annotated + * classes, set this parameter to none. + *

* The plugin does not scan for annotated classes in transitive * dependencies. If some of your annotated classes are hidden in a * transitive dependency, you can simply add that dependency explicitly. diff --git a/src/site/xhtml/pitfalls.xhtml b/src/site/xhtml/pitfalls.xhtml index 50006953..90e09241 100644 --- a/src/site/xhtml/pitfalls.xhtml +++ b/src/site/xhtml/pitfalls.xhtml @@ -151,7 +151,7 @@ mvn hibernate4:export -Dhibernate.export.force=true

executed, you can configure that explicitly like this:

->plugin<
+<plugin>
   <groupId>de.juplo</groupId>
   <artifactId>hibernate4-maven-plugin</artifactId>
   ...
@@ -163,5 +163,21 @@ mvn hibernate4:export -Dhibernate.export.force=true
Background-information for this design-decission can be found on the extra page To skip or not to skip: that is the question...

+

I do not want my dependencies to be scanned for hibernate annotations

+

+ If you do not want your dependencies to be scanned for hibernate annotations, + you can pass -Dhibernate.export.scan_dependencies=none to maven + or set scanDependencies to none in the configuration + of the plugin like this: +

+
+<plugin>
+  <groupId>de.juplo</groupId>
+  <artifactId>hibernate4-maven-plugin</artifactId>
+  ...
+  <configuration>
+    <scanDependencies>none</scanDependencies>
+  </configuration>
+</plugin>
-- 2.20.1 From 347236c3cea0f204cefd860c605d9f086e674e8b Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Tue, 11 Nov 2014 14:29:23 +0100 Subject: [PATCH 12/16] Added FAQ-entry for problem with whitespaces in the path under Windows --- src/site/xhtml/pitfalls.xhtml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/site/xhtml/pitfalls.xhtml b/src/site/xhtml/pitfalls.xhtml index 90e09241..9b868001 100644 --- a/src/site/xhtml/pitfalls.xhtml +++ b/src/site/xhtml/pitfalls.xhtml @@ -179,5 +179,25 @@ mvn hibernate4:export -Dhibernate.export.force=true
<scanDependencies>none</scanDependencies> </configuration> </plugin> +

No annotated classes found

+

+ If you are working under Windows and get the error-message + No annotated classes found in directory C:\projects\X Y Z\path-to-project\target\classes, + but you are really sure, that there are annotated classes in that + directory, you should try to rename your folders, so that their names + do not contain any whitespaces. +

+

+ So fare, I got to bug-reports considering this. + In both cases, removing all whitespaces from the path solved the error. + In both cases, I was not able to reproduce the bug on my development + system, which is running under linux. +

+

+ + Hence, I assume, this is a sublte bug in the way, the java-version for + Windows is handling paths, that contain whitespaces. + +

-- 2.20.1 From ad979a8a82a7701a891a59a183ea4be66672145b Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Tue, 11 Nov 2014 14:32:42 +0100 Subject: [PATCH 13/16] Upgraded hibernate-core, hibernate-envers, hibernate-validator and maven-core * Upgraded hibernate-core from 4.3.1.Final to 4.3.7.Final * Upgraded hibernate-envers from 4.3.1.Final to 4.3.7.Final * Upgraded hibernate-validator from 4.3.1.Final to 4.3.2.Final * Upgraded maven-core from 3.2.1 to 3.2.3 --- pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 272a1ea5..3b4fc453 100644 --- a/pom.xml +++ b/pom.xml @@ -117,10 +117,10 @@ UTF-8 - 4.3.1.Final - 4.3.1.Final - 4.3.1.Final - 3.2.1 + 4.3.7.Final + 4.3.7.Final + 4.3.2.Final + 3.2.3 1.0.1 1.0.3
-- 2.20.1 From b95416ef16bbaafecb3d40888fe97e70cdd75c77 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Tue, 11 Nov 2014 15:10:32 +0100 Subject: [PATCH 14/16] Upgraded hibernate-validator from 4.3.2.Final to 5.1.3.Final Hibernate Validator 5 requires the Unified Expression Language (EL) in version 2.2 or later. Therefore, a dependency to javax.el-api:3.0.0 was added. (Without that, the compilation of some integration-tests fails!) --- pom.xml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3b4fc453..20569f75 100644 --- a/pom.xml +++ b/pom.xml @@ -119,7 +119,8 @@ 4.3.7.Final 4.3.7.Final - 4.3.2.Final + 5.1.3.Final + 3.0.0 3.2.3 1.0.1 1.0.3 @@ -157,6 +158,11 @@ hibernate-validator ${hibernate-validator.version}
+ + javax.el + javax.el-api + ${el-api.version} + org.scannotation scannotation -- 2.20.1 From 18840e3c775584744199d8323eb681b73b98e9c4 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Tue, 11 Nov 2014 15:27:57 +0100 Subject: [PATCH 15/16] [maven-release-plugin] prepare release hibernate4-maven-plugin-1.0.5 --- pom.xml | 2 +- src/site/xhtml/index.xhtml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 20569f75..89862bc6 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ hibernate4-maven-plugin Hibernate 4 Maven Plugin Plugin for generating a database-schema from Hibernate-4-Mapping-Annotations - 1.0.5-SNAPSHOT + 1.0.5 maven-plugin http://juplo.de/hibernate4-maven-plugin diff --git a/src/site/xhtml/index.xhtml b/src/site/xhtml/index.xhtml index ef7de69c..d4568618 100644 --- a/src/site/xhtml/index.xhtml +++ b/src/site/xhtml/index.xhtml @@ -59,6 +59,7 @@
  • current version
  • ${project.version} (this version)
  • +
  • 1.0.4
  • 1.0.3
  • 1.0.2
  • 1.0.1
  • -- 2.20.1 From ec30af2068f2d12a9acf65474ca1a4cdc1aa7122 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Tue, 11 Nov 2014 15:28:12 +0100 Subject: [PATCH 16/16] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- src/site/xhtml/index.xhtml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 89862bc6..f3bfd28c 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ hibernate4-maven-plugin Hibernate 4 Maven Plugin Plugin for generating a database-schema from Hibernate-4-Mapping-Annotations - 1.0.5 + 1.0.6-SNAPSHOT maven-plugin http://juplo.de/hibernate4-maven-plugin diff --git a/src/site/xhtml/index.xhtml b/src/site/xhtml/index.xhtml index d4568618..39d191ea 100644 --- a/src/site/xhtml/index.xhtml +++ b/src/site/xhtml/index.xhtml @@ -59,6 +59,7 @@