<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
- <h2>Configuration through a hibernate.properties-File</h2>
+ <header><h1>Configuration Examples</h1></header>
+ <h2>Configuration Through A Configuration-File</h2>
<p>
The most simple way to configure the plugin is, to put all the
- hibernate-configuration in a <strong>hibernate.properties</strong>-file on your
- classpath. Put the file in the <code>resources</code>-folder. Maven will put
- it in the <code>class</code>-folder of your webapp, where it will be picked up
- by this plugin as well as by Hibernate 4.
+ hibernate-configuration in a <strong>hibernate.properties</strong>- or
+ a <strong>hibernate.cfg.xml</strong>-file on your classpath or in the
+ <strong>persistence.xml</strong>-file of your JPA-configuration, just
+ like you would do, if you are not using the
+ <code>hibernate-maven-plugin</code>.
</p>
<p>
Doing so, the only additionally configuration needed, to activat the plugin
<pre class="prettyprint linenums lang-html">
<plugin>
<groupId>de.juplo</groupId>
- <artifactId>hibernate4-maven-plugin</artifactId>
+ <artifactId>hibernate-maven-plugin</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<goals>
- <goal>export</goal>
+ <goal>create</goal>
</goals>
</execution>
</executions>
</plugin></pre>
<p>
- 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
+ <code>drop</code>:
+ </p>
+ <pre class="prettyprint linenums lang-html">
+<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></pre>
+ <p>
+ A correspondin goal for the command <code>update</code> is missing in this
+ version, but we are planning to implement it in near feature.
+ </p>
+ <p>
+ 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 <code>hibernate.properties</code>-file may look like this:
+ </p>
+ <pre class="prettyprint linenums lang-properties">
+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=</pre>
+ <p>
+ 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,
<strong>
- 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!
</strong>
</p>
<p>
- 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:
</p>
<pre class="prettyprint linenums lang-html">
<plugin>
<groupId>de.juplo</groupId>
- <artifactId>hibernate4-maven-plugin</artifactId>
+ <artifactId>hibernate-maven-plugin</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<goals>
- <goal>export</goal>
+ <goal>drop</goal>
+ <goal>create</goal>
</goals>
</execution>
</executions>
<p>
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 <a href="./export-mojo.html">Documentation of the export-Mojo</a>).
+ (for a full list see the <a href="./create-mojo.html">Documentation of the goal create</a>).
These are named after the
<a href="http://docs.jboss.org/hibernate/orm/4.1/manual/en-US/html_single/#configuration-hibernatejdbc">Hibernate JDBC Properties</a>:
</p>
<plugin>
<groupId>de.juplo</groupId>
- <artifactId>hibernate4-maven-plugin</artifactId>
+ <artifactId>hibernate-maven-plugin</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<goals>
- <goal>export</goal>
+ <goal>drop</goal>
+ <goal>create</goal>
</goals>
</execution>
</executions>
</plugin>
<plugins></pre>
+ <p>
+ 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.
+ </p>
<h2>Configuration through the plugin-configuration</h2>
<p>
A third way for configuring the plugin is the plugin-configuration.
The relevant configuration-parameters are:
</p>
<ul>
- <li><code>driverClassName</code></li>
- <li><code>hibernateDialect</code></li>
+ <li><code>driver</code></li>
+ <li><code>dialect</code></li>
<li><code>url</code></li>
<li><code>username</code></li>
<li><code>password</code></li>
<pre class="prettyprint linenums lang-html">
<plugin>
<groupId>de.juplo</groupId>
- <artifactId>hibernate4-maven-plugin</artifactId>
+ <artifactId>hibernate-maven-plugin</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<goals>
- <goal>export</goal>
+ <goal>drop</goal>
+ <goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
- <driverClassName>org.hsqldb.jdbcDriver</driverClassName>
- <hibernateDialect>org.hibernate.dialect.HSQLDialect</hibernateDialect>
+ <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>
</p>
<p>
For more explanations, see the
- <a href="./export-mojo.html">Documentation of the export-Mojo</a>.
+ <a href="./create-mojo.html">Documentation of the goal create</a>.
</p>
<h2 id="precedence">Configuration-Method-Precedence</h2>
<p>
</p>
<ol>
<li><code>hibernate.properties</code></li>
+ <li><code>hibernate.cfg.xml</code></li>
+ <li><code>persistence.xml</code></li>
<li>maven-properties</li>
<li>plugin-configuration</li>
</ol>
<p>
If you are in doubt about where a configuration-value comes from, run
- maven with the <a href="./debugging.html">debug-output</a> enabled: <code>mvn -X hibernate4:export</code>
+ maven with the <a href="./debugging.html">debug-output</a> enabled: <code>mvn -X hibernate:create</code>
and be aware, that maven-properties can be overwitten on the command-line,
in your <code>~/.m2/settings.xml</code> and in a profile.
</p>
other configuration-method.
</p>
<p>
- 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:
</p>
<pre class="prettyprint linenums lang-html">
<plugin>
<groupId>de.juplo</groupId>
- <artifactId>hibernate4-maven-plugin</artifactId>
+ <artifactId>hibernate-maven-plugin</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<goals>
- <goal>export</goal>
+ <goal>drop</goal>
+ <goal>create</goal>
</goals>
</execution>
</executions>