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 <header><h1>Configuration Examples</h1></header>
8 <h2>Configuration Through A Configuration-File</h2>
10 The most simple way to configure the plugin is, to put all the
11 hibernate-configuration in a <strong>hibernate.properties</strong>- or
12 a <strong>hibernate.cfg.xml</strong>-file on your classpath or in the
13 <strong>persistence.xml</strong>-file of your JPA-configuration, just
14 like you would do, if you are not using the
15 <code>hibernate-maven-plugin</code>.
18 Doing so, the only additionally configuration needed, to activat the plugin
19 is the following entry in the <code>plugins</code>-section of your <code>pom.xml</code>:
21 <pre class="prettyprint linenums lang-html">
23 <groupId>de.juplo</groupId>
24 <artifactId>hibernate-maven-plugin</artifactId>
25 <version>${project.version}</version>
29 <goal>create</goal>
35 This would create the configured database.
36 If you want it to be droped beforehand, you have to add the goal
39 <pre class="prettyprint linenums lang-html">
41 <groupId>de.juplo</groupId>
42 <artifactId>hibernate-maven-plugin</artifactId>
43 <version>${project.version}</version>
47 <goal>drop</goal>
48 <goal>create</goal>
54 A correspondin goal for the command <code>update</code> is missing in this
55 version, but we are planning to implement it in near feature.
58 In order to let this configuration work, your configuration file must
59 contain a complete valid configuration for the database, that you want
61 A simple example <code>hibernate.properties</code>-file may look like this:
63 <pre class="prettyprint linenums lang-properties">
64 hibernate.dialect=org.hibernate.dialect.H2Dialect
65 hibernate.connection.url=jdbc:h2:file:./target/db
66 hibernate.connection.driver_class=org.h2.Driver
67 hibernate.connection.username=sa
68 hibernate.connection.password=</pre>
70 But be aware, that using this configuration-approach the database-url,
71 that is build in the application is the same that is used while testing,
72 where the database is droped and recreated by the plugin.
75 you should never fire up this configuration on your production
76 system, or your database might be erased!
80 A better approach is, to specify a different url for testing like in the
83 <pre class="prettyprint linenums lang-html">
85 <groupId>de.juplo</groupId>
86 <artifactId>hibernate-maven-plugin</artifactId>
87 <version>${project.version}</version>
91 <goal>drop</goal>
92 <goal>create</goal>
97 <url><![CDATA[jdbc:mysql://localhost/test-db]]></url>
98 </configuration>
101 Configuration properties, that are set in the <code>configuration</code>-section
102 of the plugin-configuration cannnot be overwritten elsewere (for details
103 see <a href="#precedence">Configuration-Method-Precedence</a>).
104 You never can overwrite them by accident when specifying a property on
105 the commandline or in your <code>settings.xml</code>.
107 <h2>Configuration through maven-properties</h2>
109 Alternatively, it is possible, to configure the plugin via maven-properties.
110 Each relevant configuration-option has a corresponding maven-property
111 (for a full list see the <a href="./create-mojo.html">Documentation of the goal create</a>).
112 These are named after the
113 <a href="http://docs.jboss.org/hibernate/orm/4.1/manual/en-US/html_single/#configuration-hibernatejdbc">Hibernate JDBC Properties</a>:
116 <li><code>hibernate.connection.driver_class</code></li>
117 <li><code>hibernate.dialect</code></li>
118 <li><code>hibernate.connection.url</code></li>
119 <li><code>hibernate.connection.username</code></li>
120 <li><code>hibernate.connection.password</code></li>
123 So, instead of writing the hibernate-configuration in the properties-file,
124 like above, you could put it in the <code>properties</code>-section of your
125 <code>pom.xml</code>.
128 Thogether with the plugin-definition from above, the following would
129 be a complete configuration (again, the database-url was overwritten in
130 the plugin-configuration, to be sure to have a separate database for
133 <pre class="prettyprint linenums lang-html">
135 <hibernate.connection.driver_class>org.hsqldb.jdbcDriver</hibernate.connection.driver_class>
136 <hibernate.dialect>org.hibernate.dialect.HSQLDialect</hibernate.dialect>
137 <hibernate.connection.url><![CDATA[jdbc:hsqldb:res:org.my.path.production_db]]></hibernate.connection.url>
138 <hibernate.connection.username>sa</hibernate.connection.username>
139 <hibernate.connection.password></hibernate.connection.password>
149 <groupId>de.juplo</groupId>
150 <artifactId>hibernate-maven-plugin</artifactId>
151 <version>${project.version}</version>
155 <goal>drop</goal>
156 <goal>create</goal>
160 <configuration>
161 <url><![CDATA[jdbc:hsqldb:target/db/testdb;shutdown=true]]></url>
162 </configuration>
165 <plugins></pre>
167 This way, you can reuse the same properties to provide a
168 default-configurationthe, that is build into your application, and
169 overwrite the database-url, that is used during testing to prevent
170 accidential drops of your production database.
172 <h2>Configuration through the plugin-configuration</h2>
174 A third way for configuring the plugin is the plugin-configuration.
175 The relevant configuration-parameters are:
178 <li><code>driver</code></li>
179 <li><code>dialect</code></li>
180 <li><code>url</code></li>
181 <li><code>username</code></li>
182 <li><code>password</code></li>
185 The equivalent of the configuration from the last section would look
188 <pre class="prettyprint linenums lang-html">
190 <groupId>de.juplo</groupId>
191 <artifactId>hibernate-maven-plugin</artifactId>
192 <version>${project.version}</version>
196 <goal>drop</goal>
197 <goal>create</goal>
201 <configuration>
202 <driver>org.hsqldb.jdbcDriver</driver>
203 <dialect>org.hibernate.dialect.HSQLDialect</dialect>
204 <url><![CDATA[jdbc:hsqldb:target/db/fotos;shutdown=true]]></url>
205 <username>sa</username>
206 <password></password>
207 </configuration>
208 </plugin></pre>
210 The parameter <strong>hibernateProperties</strong> (name of the hibernate-properties-file
211 to use, defaults to <strong>hibernate.properties</strong>) can only be configured through
215 For more explanations, see the
216 <a href="./create-mojo.html">Documentation of the goal create</a>.
218 <h2 id="precedence">Configuration-Method-Precedence</h2>
220 The configuration is gathered in a fix order:
223 <li><code>hibernate.properties</code></li>
224 <li><code>hibernate.cfg.xml</code></li>
225 <li><code>persistence.xml</code></li>
226 <li>maven-properties</li>
227 <li>plugin-configuration</li>
230 If you are in doubt about where a configuration-value comes from, run
231 maven with the <a href="./debugging.html">debug-output</a> enabled: <code>mvn -X hibernate:create</code>
232 and be aware, that maven-properties can be overwitten on the command-line,
233 in your <code>~/.m2/settings.xml</code> and in a profile.
236 The plugin-configuration comes last and overwrites everything else.
237 That way, you can be sure, that a configuration-value, that is
238 specified in the plugin-configuration will never be overwritten by any
239 other configuration-method.
242 If you need to overwrite plugin-configuration-values with
243 maven-properties, you can use maven-properties in the plugin-configuration:
245 <pre class="prettyprint linenums lang-html">
247 <groupId>de.juplo</groupId>
248 <artifactId>hibernate-maven-plugin</artifactId>
249 <version>${project.version}</version>
253 <goal>drop</goal>
254 <goal>create</goal>
258 <configuration>
259 <password>${my-password-property}</password>
260 </configuration>
261 </plugin></pre>