From d2b1e427907be345b4249302aa102fa9527c4ca0 Mon Sep 17 00:00:00 2001
From: Kai Moritz 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 @@ -41,23 +43,25 @@ A better approach is, to 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
@@ -93,40 +97,41 @@
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> +org.hsqldb.jdbcDriver +org.hibernate.dialect.HSQLDialect ++ sa ++ ... - <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> -
This way, you can reuse the same properties to provide a default-configurationthe, that is build into your application, and @@ -149,27 +154,29 @@ 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 @@ -206,20 +213,21 @@ If you 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>
-
+
+```
+-mvn -X compile hibernate4:export+ +``` +mvn -X compile hibernate4:create +``` +
(The compile might be necessary, because hibernate4-maven-plugin
has to scan the compiled classes for annotations!)
diff --git a/src/site/markdown/force.md b/src/site/markdown/force.md
index b6064132..dd169baf 100644
--- a/src/site/markdown/force.md
+++ b/src/site/markdown/force.md
@@ -19,15 +19,18 @@
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/markdown/pitfalls.md b/src/site/markdown/pitfalls.md
index 9cfba8a1..45525896 100644
--- a/src/site/markdown/pitfalls.md
+++ b/src/site/markdown/pitfalls.md
@@ -20,10 +20,13 @@
This can be achieved with the command-line parameter
-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! @@ -41,7 +44,8 @@ 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 = @@ -59,7 +63,9 @@ [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. @@ -68,26 +74,29 @@ A much cleaner way is, to (additionally) ad the dependency, to the plugin-definition:
-
-<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. @@ -120,14 +129,16 @@ For example, the dbunit-plugin can be configured to skip its excecution, if hibernate4-maven-plugin was skipped like this:
-
-<plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>dbunit-maven-plugin</artifactId>
- <configuration>
- <skip>${hibernate.export.skipped}</skip>
- </configuration>
-</plugin>
+
+```
++ +``` [INFO] No modified annotated classes found and dialect unchanged. -[INFO] Skipping schema generation!+[INFO] Skipping schema generation! +``` +
If one always uses mvn clean for cleanup, this will not happen.
Otherwise the recreation must be forced:
-mvn hibernate4:create -Dhibernate.schema.force=true+ +``` +mvn hibernate4:create -Dhibernate.schema.force=true +``` ## The hibernate:create goal is not executed, when tests are skipped @@ -157,15 +173,18 @@ mvn hibernate4:create -Dhibernate.schema.force=true
maven.test.skip is set to true. If you need it to be always
executed, you can configure that explicitly like this:
- -<plugin> - <groupId>de.juplo</groupId> - <artifactId>hibernate4-maven-plugin</artifactId> + +``` +++ de.juplo +hibernate4-maven-plugin ... - <configuration> - <skip>false</skip> - </configuration> -</plugin>
Background-information for this design-decission can be found on the extra
page To skip or not to skip: that is the question...
@@ -179,15 +198,17 @@ mvn hibernate4:create -Dhibernate.schema.force=true
or set scanDependencies to none in the configuration
of the plugin like this:
-<plugin> - <groupId>de.juplo</groupId> - <artifactId>hibernate4-maven-plugin</artifactId> + +``` +++ de.juplo +hibernate4-maven-plugin ... - <configuration> - <scanDependencies>none</scanDependencies> - </configuration> -</plugin>
skip to false:
- -<plugin> - <groupId>de.juplo</groupId> - <artifactId>hibernate4-maven-plugin</artifactId> + +``` +++ de.juplo +hibernate4-maven-plugin ... - <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> + +``` +++ de.juplo +hibernate4-maven-plugin ... - <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
--
2.39.5