From: Kai Moritz plugins-section of your pom.xml:
-<plugin>
- <groupId>de.juplo</groupId>
- <artifactId>hibernate-maven-plugin</artifactId>
- <version>${project.version}</version>
- <executions>
- <execution>
- <goals>
- <goal>create</goal>
- </goals>
- </execution>
- </executions>
-</plugin>
-
+
+```
+
This would create the configured database.
If you want it to be droped beforehand, you have to add the goal
drop:
-<plugin>
- <groupId>de.juplo</groupId>
- <artifactId>hibernate-maven-plugin</artifactId>
- <version>${project.version}</version>
- <executions>
- <execution>
- <goals>
- <goal>drop</goal>
- <goal>create</goal>
- </goals>
- </execution>
- </executions>
-</plugin>
-
+
+```
+
A correspondin goal for the command update is missing in this
version, but we are planning to implement it in near feature.
@@ -58,13 +62,15 @@
to use.
A simple example hibernate.properties-file may look like this:
+ +``` hibernate.dialect=org.hibernate.dialect.H2Dialect hibernate.connection.url=jdbc:h2:file:./target/db hibernate.connection.driver_class=org.h2.Driver hibernate.connection.username=sa hibernate.connection.password= -+``` +
But be aware, that using this configuration-approach the database-url, that is build in the application is the same that is used while testing, @@ -79,24 +85,26 @@ hibernate.connection.password= A better approach is, to specify a different url for testing like in the following snippet:
-
-<plugin>
- <groupId>de.juplo</groupId>
- <artifactId>hibernate-maven-plugin</artifactId>
- <version>${project.version}</version>
- <executions>
- <execution>
- <goals>
- <goal>drop</goal>
- <goal>create</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
@@ -132,42 +140,42 @@ hibernate.connection.password=
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>hibernate-maven-plugin</artifactId> - <version>${project.version}</version> - <executions> - <execution> - <goals> - <goal>drop</goal> - <goal>create</goal> - </goals> - </execution> - </executions> - <configuration> - <url><![CDATA[jdbc:hsqldb:target/db/testdb;shutdown=true]]></url> - </configuration> - </plugin> + + -<plugins> +de.juplo +hibernate-maven-plugin +${project.version} ++ ++ ++ +drop +create ++ ++ +``` -
This way, you can reuse the same properties to provide a default-configurationthe, that is build into your application, and @@ -190,28 +198,30 @@ hibernate.connection.password= The equivalent of the configuration from the last section would look like this:
-
-<plugin>
- <groupId>de.juplo</groupId>
- <artifactId>hibernate-maven-plugin</artifactId>
- <version>${project.version}</version>
- <executions>
- <execution>
- <goals>
- <goal>drop</goal>
- <goal>create</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <driver>org.hsqldb.jdbcDriver</driver>
- <dialect>org.hibernate.dialect.HSQLDialect</dialect>
- <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 @@ -250,21 +260,22 @@ hibernate.connection.password= 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>hibernate-maven-plugin</artifactId>
- <version>${project.version}</version>
- <executions>
- <execution>
- <goals>
- <goal>drop</goal>
- <goal>create</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <password>${my-password-property}</password>
- </configuration>
-</plugin>
-
+
+```
+-mvn -X compile hibernate:create+ +``` +mvn -X compile hibernate:create +``` +
(The compile might be necessary, because hibernate-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 85982465..26dbd9a9 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>hibernate-maven-plugin</artifactId>
- <version>${project.version}</version>
- <configuration>
- <force>true</force>
- </configuration>
-</plugin>
+
+```
+
Or you may specify -Dhibernate.schema.force=true at the command line,
if you want to force hibernate-maven-plugin only once.
diff --git a/src/site/markdown/pitfalls.md b/src/site/markdown/pitfalls.md
index 13bfd988..f86f79b5 100644
--- a/src/site/markdown/pitfalls.md
+++ b/src/site/markdown/pitfalls.md
@@ -25,10 +25,13 @@
-Dhibernate.schema.export=false or with the following
configuration:
-<configuration> - <export>false</export> -</configuration>+ +``` +
But even when no database is to be created, hibernate always needs to know the dialect. Hence, the plugin will still fail, if this parameter is also @@ -47,7 +50,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 =
@@ -70,13 +74,15 @@
[INFO] Finished at: Mon Mar 07 19:06:54 CET 2016
[INFO] Final Memory: 11M/215M
[INFO] ------------------------------------------------------------------------
-[ERROR] Failed to execute goal de.juplo:hibernate-maven-plugin:${project.version}:drop (default) on project hibernate4-properties-test: Could not open the JDBC-connection: Unable to load class [org.h2.Driver]: Could not load requested class : org.h2.Driver -> [Help 1]
+[ERROR] Failed to execute goal de.juplo:hibernate-maven-plugin:${project.version}:drop (default) on project hibernate4-properties-test: Could not open the JDBC-connection: Unable to load class [org.h2.Driver]: Could not load requested class : org.h2.Driver -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
-[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
+[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
+```
+
A quick workaround for this error would be, to delete the runtime-constraint for the jdbc-driver-dependency. @@ -85,27 +91,30 @@ A much cleaner way is, to (additionally) ad the dependency, to the plugin-definition:
-
-<plugin>
- <groupId>de.juplo</groupId>
- <artifactId>hibernate-maven-plugin</artifactId>
- <version>${project.version}</version>
- <executions>
- <execution>
- <goals>
- <goal>drop</goal>
- <goal>create</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. @@ -138,14 +147,16 @@ For example, the dbunit-plugin can be configured to skip its excecution, if hibernate-maven-plugin was skipped like this:
-
-<plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>dbunit-maven-plugin</artifactId>
- <configuration>
- <skip>${hibernate.schema.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 hibernate:create -Dhibernate.schema.force=true+``` +mvn hibernate:create -Dhibernate.schema.force=true +``` ## The hibernate:create goal is not executed, when tests are skipped @@ -175,15 +190,18 @@ mvn hibernate: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>hibernate-maven-plugin</artifactId> + +``` +++ de.juplo +hibernate-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...
@@ -197,15 +215,17 @@ mvn hibernate:create -Dhibernate.schema.force=true
or set scanDependencies to none in the configuration
of the plugin like this:
-<plugin> - <groupId>de.juplo</groupId> - <artifactId>hibernate-maven-plugin</artifactId> + +``` +++ de.juplo +hibernate-maven-plugin ... - <configuration> - <scanDependencies>none</scanDependencies> - </configuration> -</plugin>
skip to false:
- -<plugin> - <groupId>de.juplo</groupId> - <artifactId>hibernate-maven-plugin</artifactId> + +``` +++ de.juplo +hibernate-maven-plugin ... - <configuration> - <skip>false</skip> - </configuration> -</plugin>
Or, if you want the plugin 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>hibernate-maven-plugin</artifactId> + +``` +++ de.juplo +hibernate-maven-plugin ... - <configuration> - <skip>${foo.bar}</skip> - </configuration> -</plugin>
This way, the plugin would be skipped, if you set the property
foo.bar to true. For example, if you specify -Dfoo.bar=true