From e77db69bf68a032545d12b0a73cc51a69483604a Mon Sep 17 00:00:00 2001
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
@@ -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 8e036a72..9ce1ae10 100644
--- a/src/site/markdown/force.md
+++ b/src/site/markdown/force.md
@@ -20,15 +20,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 558c1520..3b0ffe88 100644
--- a/src/site/markdown/pitfalls.md
+++ b/src/site/markdown/pitfalls.md
@@ -24,10 +24,13 @@
-Dhibernate.schema.execute=false or with the following
configuration:
-<configuration> - <execute>false</execute> -</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 @@ -46,7 +49,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 =
@@ -69,13 +73,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. @@ -84,27 +90,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. @@ -137,14 +146,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 @@ -174,15 +189,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...
@@ -196,15 +214,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>
Example configuration for two goals:
--<executions> - <execution> - <id>Create Drop-Schema</id> - <phase>test-compile</phase> - <goals> - <goal>drop</goal> - </goals> - <configuration> - <outputFile>db-schema/drop-schema.ddl</outputFile> - </configuration> - </execution> - <execution> - <id>Create Create-Schema</id> - <phase>test-compile</phase> - <goals> - <goal>create</goal> - </goals> - <configuration> - <outputFile>db-schema/create-schema.ddl</outputFile> - </configuration> - </execution> -</executions> -+ +``` +
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
--
2.39.5