2 <!-- Generated by Apache Maven Doxia Site Renderer 1.6 at 2016-03-09 -->
3 <!-- Current: configuration.html -->
4 <!-- Active: index.html -->
5 <!-- Path: [index.html, configuration.html] -->
6 <!-- Skiplist: [index.html, configuration.html, create-mojo.html, drop-mojo.html, debugging.html, skip.html, force.html, pitfalls.html] -->
9 <title>juplo - Hibernate Maven Plugin - Configuration Examples</title>
10 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
11 <link rel="canonical" href="http://juplo.de/hibernate-maven-plugin/configuration.html"/>
12 <meta name="viewport" content="width=device-width, initial-scale=1" />
13 <link rel="stylesheet" type="text/css" href="/css/base.css" />
14 <style type="text/css">
15 @import '/css/screen.css' screen;
17 <script src="/js/prettify.js"></script>
19 <script src="/js/html5shiv.js"></script>
22 <link rel="stylesheet" type="text/css" href="/css/ie8.css" />
24 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
26 <body class="menu" onload="prettyPrint()">
27 <div id="page" class="cf">
29 <h1 id="logo"><a href="/" title="Home" class="l">juplo</a></h1>
30 <span id="slogan"><strong>Java</strong> bits from nerds for nerds</span>
34 <strong class="b title">You are here:</strong>
36 <li class="b"><a class="b" href="/">Home</a></li>
37 <li class="b"><a class="b" href="/projects.html">Projects</a></li>
38 <li class="b"><a class="b" href="./index.html">Hibernate Maven Plugin</a></li>
39 <li class="b"><strong class="b">Configuration Examples</strong></li>
41 <a class="hide" href="#navigation">Jump to navigation</a>
44 <main class="content cf">
45 <article id="content" class="main">
46 <header><h1>Configuration Examples</h1></header>
52 <h2><a name="Configuration_Through_A_Configuration-File"></a>Configuration Through A Configuration-File</h2>
55 The most simple way to configure the plugin is, to put all the
56 hibernate-configuration in a <b>hibernate.properties</b>- or
57 a <b>hibernate.cfg.xml</b>-file on your classpath or in the
58 <b>persistence.xml</b>-file of your JPA-configuration, just
59 like you would do, if you are not using the
60 <tt>hibernate-maven-plugin</tt>.
64 Doing so, the only additionally configuration needed, to activat the plugin
65 is the following entry in the <tt>plugins</tt>-section of your <tt>pom.xml</tt>:
69 <pre class="prettyprint linenums lang-html">
71 <groupId>de.juplo</groupId>
72 <artifactId>hibernate-maven-plugin</artifactId>
73 <version>2.0.0</version>
77 <goal>create</goal>
81 </plugin></pre></div>
84 This would create the configured database.
85 If you want it to be droped beforehand, you have to add the goal
90 <pre class="prettyprint linenums lang-html">
92 <groupId>de.juplo</groupId>
93 <artifactId>hibernate-maven-plugin</artifactId>
94 <version>2.0.0</version>
98 <goal>drop</goal>
99 <goal>create</goal>
103 </plugin></pre></div>
106 A correspondin goal for the command <tt>update</tt> is missing in this
107 version, but we are planning to implement it in near feature.
111 In order to let this configuration work, your configuration file must
112 contain a complete valid configuration for the database, that you want
114 A simple example <tt>hibernate.properties</tt>-file may look like this:
118 <pre class="prettyprint linenums lang-properties">
119 hibernate.dialect=org.hibernate.dialect.H2Dialect
120 hibernate.connection.url=jdbc:h2:file:./target/db
121 hibernate.connection.driver_class=org.h2.Driver
122 hibernate.connection.username=sa
123 hibernate.connection.password=</pre></div>
126 But be aware, that using this configuration-approach the database-url,
127 that is build in the application is the same that is used while testing,
128 where the database is droped and recreated by the plugin.
131 you should never fire up this configuration on your production
132 system, or your database might be erased!
137 A better approach is, to specify a different url for testing like in the
142 <pre class="prettyprint linenums lang-html">
144 <groupId>de.juplo</groupId>
145 <artifactId>hibernate-maven-plugin</artifactId>
146 <version>2.0.0</version>
150 <goal>drop</goal>
151 <goal>create</goal>
155 <configuration>
156 <url><![CDATA[jdbc:mysql://localhost/test-db]]></url>
157 </configuration>
158 </plugin></pre></div>
161 Configuration properties, that are set in the <tt>configuration</tt>-section
162 of the plugin-configuration cannnot be overwritten elsewere (for details
163 see <a href="#precedence">Configuration-Method-Precedence</a>).
164 You never can overwrite them by accident when specifying a property on
165 the commandline or in your <tt>settings.xml</tt>.
168 <div class="section">
169 <h2><a name="Configuration_through_maven-properties"></a>Configuration through maven-properties</h2>
172 Alternatively, it is possible, to configure the plugin via maven-properties.
173 Each relevant configuration-option has a corresponding maven-property
174 (for a full list see the <a href="./create-mojo.html">Documentation of the goal create</a>).
175 These are named after the
176 <a class="externalLink" href="http://docs.jboss.org/hibernate/orm/4.1/manual/en-US/html_single/#configuration-hibernatejdbc">Hibernate JDBC Properties</a>:
181 <li><tt>hibernate.connection.driver_class</tt></li>
183 <li><tt>hibernate.dialect</tt></li>
185 <li><tt>hibernate.connection.url</tt></li>
187 <li><tt>hibernate.connection.username</tt></li>
189 <li><tt>hibernate.connection.password</tt></li>
193 So, instead of writing the hibernate-configuration in the properties-file,
194 like above, you could put it in the <tt>properties</tt>-section of your
199 Thogether with the plugin-definition from above, the following would
200 be a complete configuration (again, the database-url was overwritten in
201 the plugin-configuration, to be sure to have a separate database for
206 <pre class="prettyprint linenums lang-html">
208 <hibernate.connection.driver_class>org.hsqldb.jdbcDriver</hibernate.connection.driver_class>
209 <hibernate.dialect>org.hibernate.dialect.HSQLDialect</hibernate.dialect>
210 <hibernate.connection.url><![CDATA[jdbc:hsqldb:res:org.my.path.production_db]]></hibernate.connection.url>
211 <hibernate.connection.username>sa</hibernate.connection.username>
212 <hibernate.connection.password></hibernate.connection.password>
222 <groupId>de.juplo</groupId>
223 <artifactId>hibernate-maven-plugin</artifactId>
224 <version>2.0.0</version>
228 <goal>drop</goal>
229 <goal>create</goal>
233 <configuration>
234 <url><![CDATA[jdbc:hsqldb:target/db/testdb;shutdown=true]]></url>
235 </configuration>
238 <plugins></pre></div>
241 This way, you can reuse the same properties to provide a
242 default-configurationthe, that is build into your application, and
243 overwrite the database-url, that is used during testing to prevent
244 accidential drops of your production database.
247 <div class="section">
248 <h2><a name="Configuration_through_the_plugin-configuration"></a>Configuration through the plugin-configuration</h2>
251 A third way for configuring the plugin is the plugin-configuration.
252 The relevant configuration-parameters are:
257 <li><tt>driver</tt></li>
259 <li><tt>dialect</tt></li>
261 <li><tt>url</tt></li>
263 <li><tt>username</tt></li>
265 <li><tt>password</tt></li>
269 The equivalent of the configuration from the last section would look
274 <pre class="prettyprint linenums lang-html">
276 <groupId>de.juplo</groupId>
277 <artifactId>hibernate-maven-plugin</artifactId>
278 <version>2.0.0</version>
282 <goal>drop</goal>
283 <goal>create</goal>
287 <configuration>
288 <driver>org.hsqldb.jdbcDriver</driver>
289 <dialect>org.hibernate.dialect.HSQLDialect</dialect>
290 <url><![CDATA[jdbc:hsqldb:target/db/fotos;shutdown=true]]></url>
291 <username>sa</username>
292 <password></password>
293 </configuration>
294 </plugin></pre></div>
297 The parameter <b>hibernateProperties</b> (name of the hibernate-properties-file
298 to use, defaults to <b>hibernate.properties</b>) can only be configured through
303 For more explanations, see the
304 <a href="./create-mojo.html">Documentation of the goal create</a>.
307 <div class="section" id="precedence">
308 <h2 id="precedence">Configuration-Method-Precedence</h2>
311 The configuration is gathered in a fix order:
314 <ol style="list-style-type: decimal">
316 <li><tt>hibernate.properties</tt></li>
318 <li><tt>hibernate.cfg.xml</tt></li>
320 <li><tt>persistence.xml</tt></li>
322 <li>maven-properties</li>
324 <li>plugin-configuration</li>
328 If you are in doubt about where a configuration-value comes from, run
329 maven with the <a href="./debugging.html">debug-output</a> enabled: <tt>mvn -X hibernate:create</tt>
330 and be aware, that maven-properties can be overwitten on the command-line,
331 in your <tt>~/.m2/settings.xml</tt> and in a profile.
335 The plugin-configuration comes last and overwrites everything else.
336 That way, you can be sure, that a configuration-value, that is
337 specified in the plugin-configuration will never be overwritten by any
338 other configuration-method.
342 If you need to overwrite plugin-configuration-values with
343 maven-properties, you can use maven-properties in the plugin-configuration:
347 <pre class="prettyprint linenums lang-html">
349 <groupId>de.juplo</groupId>
350 <artifactId>hibernate-maven-plugin</artifactId>
351 <version>2.0.0</version>
355 <goal>drop</goal>
356 <goal>create</goal>
360 <configuration>
361 <password>${my-password-property}</password>
362 </configuration>
363 </plugin></pre></div>
367 <div class="marginal">
370 <a id="navigation"></a>
371 <a class="hide" href="#top" title="Show Content">Jump back to the top of the page</a>
372 <h2 class="nav menu">Section-Menu</h2>
374 <li class="m blog"><a href="/blog/" class="m">Blog</a></li>
375 <li class="m projects"><a href="/projects.html" class="m selected">Projects</a></li>
376 <li class="m about"><a href="/about.html" class="m">About</a></li>
378 <h2 class="nav submenu">
379 <span class="s">Submenu for section</span>
380 <a class="s selected" href="/projects.html">Projects</a>
382 <ul id="submenu" class="s">
384 <a class="s selected" href="./index.html">Hibernate Maven Plugin</a>
385 <ul class="s active">
387 <strong class="s">Configuration Examples</strong>
390 <a href="create-mojo.html" class="s" title="Goal: CREATE">Goal: CREATE</a>
393 <a href="drop-mojo.html" class="s" title="Goal: DROP">Goal: DROP</a>
396 <a href="debugging.html" class="s" title="Enable Debug-Output">Enable Debug-Output</a>
399 <a href="skip.html" class="s" title="Skipping Execution">Skipping Execution</a>
402 <a href="force.html" class="s" title="Force Exceution">Force Exceution</a>
405 <a href="pitfalls.html" class="s" title="Known Pitfalls (FAQ)">Known Pitfalls (FAQ)</a>
408 <a href="project-info.html" class="s" title="Project Information">Project Information</a>
411 <a href="project-reports.html" class="s" title="Project Reports">Project Reports</a>
419 <a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy">
420 <img class="poweredBy" alt="Built by Maven" src="./images/logos/maven-feather.png" />
427 <ul id="footerlinks">
428 <li class="f" id="copyright">© <strong>mo</strong> 2016
430 <li class="f"><a class="f" href="/impressum.html">Impressum</a></li>
431 <li class="f about"><a class="f" href="/about.html">About</a></li>
435 <script type="text/javascript"><!--//--><![CDATA[//><!--
436 var _gaq = _gaq || [];
437 _gaq.push(['_setAccount', 'UA-571104-3']);
438 _gaq.push(['_trackPageview']);
440 var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
441 ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
442 var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);