X-Git-Url: https://juplo.de/gitweb/?p=hibernate4-maven-plugin;a=blobdiff_plain;f=src%2Fsite%2Fxhtml%2Fconfiguration.xhtml;h=712bdfb4c94336363ee6e92af05ef43cee48a31d;hp=e8c5afd592af9b47d6386318ab06904108bcf02c;hb=0611db682bc69b80d8567bf9316668a1b6161725;hpb=4940080670944a15916c68fb294e18a6bfef12d5 diff --git a/src/site/xhtml/configuration.xhtml b/src/site/xhtml/configuration.xhtml index e8c5afd5..712bdfb4 100644 --- a/src/site/xhtml/configuration.xhtml +++ b/src/site/xhtml/configuration.xhtml @@ -4,13 +4,14 @@ -

Configuration through a hibernate.properties-File

+

Configuration Through A Configuration-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. + hibernate-configuration in a hibernate.properties- or + a hibernate.cfg.xml-file on your classpath or in the + persistence.xml-file of your JPA-configuration, just + like you would do, if you are not using the + hibernate-maven-plugin.

Doing so, the only additionally configuration needed, to activat the plugin @@ -24,15 +25,50 @@ <executions> <execution> <goals> - <goal>export</goal> + <goal>create</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. + 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. +

+

+ In order to let this configuration work, your configuration file must + contain a complete valid configuration for the database, that you want + 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, + where the database is droped and recreated by the plugin. Because of that, you should never fire up this configuration on your production @@ -51,7 +87,8 @@ <executions> <execution> <goals> - <goal>export</goal> + <goal>drop</goal> + <goal>create</goal> </goals> </execution> </executions> @@ -70,7 +107,7 @@

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). + (for a full list see the Documentation of the goal create). These are named after the Hibernate JDBC Properties:

@@ -114,7 +151,8 @@ <executions> <execution> <goals> - <goal>export</goal> + <goal>drop</goal> + <goal>create</goal> </goals> </execution> </executions> @@ -124,6 +162,12 @@ </plugin> <plugins> +

+ This way, you can reuse the same properties to provide a + default-configurationthe, that is build into your application, and + overwrite the database-url, that is used during testing to prevent + accidential drops of your production database. +

Configuration through the plugin-configuration

A third way for configuring the plugin is the plugin-configuration. @@ -148,7 +192,8 @@ <executions> <execution> <goals> - <goal>export</goal> + <goal>drop</goal> + <goal>create</goal> </goals> </execution> </executions> @@ -167,7 +212,7 @@

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

Configuration-Method-Precedence

@@ -182,7 +227,7 @@

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

@@ -204,7 +249,8 @@ <executions> <execution> <goals> - <goal>export</goal> + <goal>drop</goal> + <goal>create</goal> </goals> </execution> </executions>