1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
7 <h2>Configuration Through A Configuration-File</h2>
9 The most simple way to configure the plugin is, to put all the
10 hibernate-configuration in a <strong>hibernate.properties</strong>- or
11 a <strong>hibernate.cfg.xml</strong>-file on your classpath or in the
12 <strong>persistence.xml</strong>-file of your JPA-configuration, just
13 like you would do, if you are not using the
14 <code>hibernate-maven-plugin</code>.
17 Doing so, the only additionally configuration needed, to activat the plugin
18 is the following entry in the <code>plugins</code>-section of your <code>pom.xml</code>:
20 <pre class="prettyprint linenums lang-html">
22 <groupId>de.juplo</groupId>
23 <artifactId>hibernate-maven-plugin</artifactId>
24 <version>${project.version}</version>
28 <goal>create</goal>
34 This would create the configured database.
35 If you want it to be droped beforehand, you have to add the goal
38 <pre class="prettyprint linenums lang-html">
40 <groupId>de.juplo</groupId>
41 <artifactId>hibernate-maven-plugin</artifactId>
42 <version>${project.version}</version>
46 <goal>drop</goal>
47 <goal>create</goal>
53 A correspondin goal for the command <code>update</code> is missing in this
54 version, but we are planning to implement it in near feature.
57 In order to let this configuration work, your configuration file must
58 contain a complete valid configuration for the database, that you want
60 A simple example <code>hibernate.properties</code>-file may look like this:
62 <pre class="prettyprint linenums lang-properties">
63 hibernate.dialect=org.hibernate.dialect.H2Dialect
64 hibernate.connection.url=jdbc:h2:file:./target/db
65 hibernate.connection.driver_class=org.h2.Driver
66 hibernate.connection.username=sa
67 hibernate.connection.password=</pre>
69 But be aware, that using this configuration-approach the database-url,
70 that is build in the application is the same that is used while testing,
71 where the database is droped and recreated by the plugin.
74 you should never fire up this configuration on your production
75 system, or your database might be erased!
79 A better approach is, to specify a different url for testing like in the
82 <pre class="prettyprint linenums lang-html">
84 <groupId>de.juplo</groupId>
85 <artifactId>hibernate-maven-plugin</artifactId>
86 <version>${project.version}</version>
90 <goal>drop</goal>
91 <goal>create</goal>
96 <url><![CDATA[jdbc:mysql://localhost/test-db]]></url>
97 </configuration>
100 Configuration properties, that are set in the <code>configuration</code>-section
101 of the plugin-configuration cannnot be overwritten elsewere (for details
102 see <a href="#precedence">Configuration-Method-Precedence</a>).
103 You never can overwrite them by accident when specifying a property on
104 the commandline or in your <code>settings.xml</code>.
106 <h2>Configuration through maven-properties</h2>
108 Alternatively, it is possible, to configure the plugin via maven-properties.
109 Each relevant configuration-option has a corresponding maven-property
110 (for a full list see the <a href="./create-mojo.html">Documentation of the goal create</a>).
111 These are named after the
112 <a href="http://docs.jboss.org/hibernate/orm/4.1/manual/en-US/html_single/#configuration-hibernatejdbc">Hibernate JDBC Properties</a>:
115 <li><code>hibernate.connection.driver_class</code></li>
116 <li><code>hibernate.dialect</code></li>
117 <li><code>hibernate.connection.url</code></li>
118 <li><code>hibernate.connection.username</code></li>
119 <li><code>hibernate.connection.password</code></li>
122 So, instead of writing the hibernate-configuration in the properties-file,
123 like above, you could put it in the <code>properties</code>-section of your
124 <code>pom.xml</code>.
127 Thogether with the plugin-definition from above, the following would
128 be a complete configuration (again, the database-url was overwritten in
129 the plugin-configuration, to be sure to have a separate database for
132 <pre class="prettyprint linenums lang-html">
134 <hibernate.connection.driver_class>org.hsqldb.jdbcDriver</hibernate.connection.driver_class>
135 <hibernate.dialect>org.hibernate.dialect.HSQLDialect</hibernate.dialect>
136 <hibernate.connection.url><![CDATA[jdbc:hsqldb:res:org.my.path.production_db]]></hibernate.connection.url>
137 <hibernate.connection.username>sa</hibernate.connection.username>
138 <hibernate.connection.password></hibernate.connection.password>
148 <groupId>de.juplo</groupId>
149 <artifactId>hibernate-maven-plugin</artifactId>
150 <version>${project.version}</version>
154 <goal>drop</goal>
155 <goal>create</goal>
159 <configuration>
160 <url><![CDATA[jdbc:hsqldb:target/db/testdb;shutdown=true]]></url>
161 </configuration>
164 <plugins></pre>
166 This way, you can reuse the same properties to provide a
167 default-configurationthe, that is build into your application, and
168 overwrite the database-url, that is used during testing to prevent
169 accidential drops of your production database.
171 <h2>Configuration through the plugin-configuration</h2>
173 A third way for configuring the plugin is the plugin-configuration.
174 The relevant configuration-parameters are:
177 <li><code>driver</code></li>
178 <li><code>dialect</code></li>
179 <li><code>url</code></li>
180 <li><code>username</code></li>
181 <li><code>password</code></li>
184 The equivalent of the configuration from the last section would look
187 <pre class="prettyprint linenums lang-html">
189 <groupId>de.juplo</groupId>
190 <artifactId>hibernate-maven-plugin</artifactId>
191 <version>${project.version}</version>
195 <goal>drop</goal>
196 <goal>create</goal>
200 <configuration>
201 <driver>org.hsqldb.jdbcDriver</driver>
202 <dialect>org.hibernate.dialect.HSQLDialect</dialect>
203 <url><![CDATA[jdbc:hsqldb:target/db/fotos;shutdown=true]]></url>
204 <username>sa</username>
205 <password></password>
206 </configuration>
207 </plugin></pre>
209 The parameter <strong>hibernateProperties</strong> (name of the hibernate-properties-file
210 to use, defaults to <strong>hibernate.properties</strong>) can only be configured through
214 For more explanations, see the
215 <a href="./create-mojo.html">Documentation of the goal create</a>.
217 <h2 id="precedence">Configuration-Method-Precedence</h2>
219 The configuration is gathered in a fix order:
222 <li><code>hibernate.properties</code></li>
223 <li><code>hibernate.cfg.xml</code></li>
224 <li><code>persistence.xml</code></li>
225 <li>maven-properties</li>
226 <li>plugin-configuration</li>
229 If you are in doubt about where a configuration-value comes from, run
230 maven with the <a href="./debugging.html">debug-output</a> enabled: <code>mvn -X hibernate:create</code>
231 and be aware, that maven-properties can be overwitten on the command-line,
232 in your <code>~/.m2/settings.xml</code> and in a profile.
235 The plugin-configuration comes last and overwrites everything else.
236 That way, you can be sure, that a configuration-value, that is
237 specified in the plugin-configuration will never be overwritten by any
238 other configuration-method.
241 If you need to overwrite plugin-configuration-values with
242 maven-properties, you can use maven-properties in the plugin-configuration:
244 <pre class="prettyprint linenums lang-html">
246 <groupId>de.juplo</groupId>
247 <artifactId>hibernate-maven-plugin</artifactId>
248 <version>${project.version}</version>
252 <goal>drop</goal>
253 <goal>create</goal>
257 <configuration>
258 <password>${my-password-property}</password>
259 </configuration>
260 </plugin></pre>