2 <!-- Generated by Apache Maven Doxia Site Renderer 1.4 at 2014-04-29 -->
3 <!-- Current: configuration.html -->
4 <!-- Active: index.html -->
5 <!-- Path: [index.html, configuration.html] -->
6 <!-- Skiplist: [index.html, configuration.html, export-mojo.html, debugging.html, force.html, pitfalls.html] -->
9 <title>juplo - Hibernate 4 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/hibernate4-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;
16 @import '/css/print.css' print;
18 <script src="/js/base.js"></script>
20 <link rel="stylesheet" type="text/css" href="/css/ie8.css" />
21 <script src="/js/ie8.js"></script>
24 <script src="/js/ie7.js"></script>
27 <script src="/js/ie6.js"></script>
29 <meta name="Date-Revision-yyyymmdd" content="20140429" />
30 <meta http-equiv="Content-Language" content="en" />
33 <body id="top" class="menu" onload="prettyPrint()">
34 <div id="page" class="cf">
36 <h1 id="logo"><a href="/" title="Home" class="l">juplo</a></h1>
37 <span id="slogan"><strong>Java</strong> bits from nerds for nerds</span>
41 <strong class="b title">You are here:</strong>
43 <li class="b"><a class="b" href="/">Home</a></li>
44 <li class="b"><a class="b" href="/projects.html">Projects</a></li>
45 <li class="b"><a class="b" href="./index.html">Hibernate 4 Maven Plugin</a </li>
46 <li class="b"><strong class="b">Configuration Examples</strong></li>
48 <a class="hide" href="#nav" title="Show navigation menu">Jump to navigation</a>
51 <main class="content cf">
52 <section id="content" class="main">
53 <h1>Hibernate 4 Maven Plugin - Configuration Examples</h1>
55 <h2>Configuration Examples<a name="Configuration_Examples"></a></h2>
57 <h3>Configuration through a hibernate.properties-File<a name="Configuration_through_a_hibernate.properties-File"></a></h3>
58 <p>The most simple way to configure the plugin is, to put all the hibernate-configuration in a <b>hibernate.properties</b>-file on your classpath. Put the file in the <tt>resources</tt>-folder. Maven will put it in the <tt>class</tt>-folder of your webapp, where it will be picked up by this plugin as well as by Hibernate 4.</p>
59 <p>Doing so, the only additionally configuration needed, to activat the plugin is the following entry in the <tt>plugins</tt>-section of your <tt>pom.xml</tt>:</p>
62 <groupId>de.juplo</groupId>
63 <artifactId>hibernate4-maven-plugin</artifactId>
64 <version>${project.version}</version>
68 <goal>export</goal>
72 </plugin></pre></div>
73 <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. <tt>So, you should never fire up this configuration on your production system, or your database might be erased!</tt></p>
74 <p>Hence, you should specify a different url for testing like in the following snippet:</p>
77 <groupId>de.juplo</groupId>
78 <artifactId>hibernate4-maven-plugin</artifactId>
79 <version>${project.version}</version>
83 <goal>export</goal>
88 <url><![CDATA[jdbc:mysql://localhost/test-db]]></url>
89 </configuration>
90 </plugin></pre></div>
91 <p>Configuration properties, that are set in the <tt>configuration</tt>-section of the plugin-configuration cannnot be overwritten elsewere (for details see <a href="#Configuration-Method-Precedence">Configuration-Method-Precedence</a>). You never can overwrite them by accident when specifying a property on the commandline or in your <tt>settings.xml</tt>.</p></div>
93 <h3>Configuration through maven-properties<a name="Configuration_through_maven-properties"></a></h3>
94 <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>). These are named after the <a class="externalLink" href="http://docs.jboss.org/hibernate/orm/4.1/manual/en-US/html_single/#configuration-hibernatejdbc"> Hibernate JDBC Properties</a>:</p>
96 <li><tt>hibernate.connection.driver_class</tt></li>
97 <li><tt>hibernate.dialect</tt></li>
98 <li><tt>hibernate.connection.url</tt></li>
99 <li><tt>hibernate.connection.username</tt></li>
100 <li><tt>hibernate.connection.password</tt></li></ul>
101 <p>So, instead of writing the hibernate-configuration in the properties-file, like above, you could put it in the <tt>properties</tt>-section of your <tt>pom.xml</tt>.</p>
102 <p>Thogether with the plugin-definition from above, the following would be a complete configuration (again, the database-url was overwritten in the plugin-configuration, to be sure to have a separate database for testing):</p>
104 <pre><properties>
105 <hibernate.connection.driver_class>org.hsqldb.jdbcDriver</hibernate.connection.driver_class>
106 <hibernate.dialect>org.hibernate.dialect.HSQLDialect</hibernate.dialect>
107 <hibernate.connection.url><![CDATA[jdbc:hsqldb:res:org.my.path.production_db]]></hibernate.connection.url>
108 <hibernate.connection.username>sa</hibernate.connection.username>
109 <hibernate.connection.password></hibernate.connection.password>
119 <groupId>de.juplo</groupId>
120 <artifactId>hibernate4-maven-plugin</artifactId>
121 <version>${project.version}</version>
125 <goal>export</goal>
129 <configuration>
130 <url><![CDATA[jdbc:hsqldb:target/db/testdb;shutdown=true]]></url>
131 </configuration>
134 <plugins></pre></div></div>
135 <div class="section">
136 <h3>Configuration through the plugin-configuration<a name="Configuration_through_the_plugin-configuration"></a></h3>
137 <p>A third way for configuring the plugin is the plugin-configuration. The relevant configuration-parameters are:</p>
139 <li><tt>driverClassName</tt></li>
140 <li><tt>hibernateDialect</tt></li>
141 <li><tt>url</tt></li>
142 <li><tt>username</tt></li>
143 <li><tt>password</tt></li></ul>
144 <p>The equivalent of the configuration from the last section would look like this:</p>
147 <groupId>de.juplo</groupId>
148 <artifactId>hibernate4-maven-plugin</artifactId>
149 <version>${project.version}</version>
153 <goal>export</goal>
157 <configuration>
158 <driverClassName>org.hsqldb.jdbcDriver</driverClassName>
159 <hibernateDialect>org.hibernate.dialect.HSQLDialect</hibernateDialect>
160 <url><![CDATA[jdbc:hsqldb:target/db/fotos;shutdown=true]]></url>
161 <username>sa</username>
162 <password></password>
163 </configuration>
164 </plugin></pre></div>
165 <p>There are some seldom used parameters, that can only be configured throug this method:</p>
167 <li><b>delimiter</b> the delimiter used in the generated sql-script</li>
168 <li><b>format</b> wether the generated sql-script is formatted, or not</li>
169 <li><b>hibernateProperties</b> name of the hibernate-properties-file</li>
170 <li><b>outputFile</b> name of the generated sql-script</li>
171 <li><b>target</b> create database or generate sql-script or both</li>
172 <li><b>type</b> create or drop the database or do both or nothing (just validate the annotation-configuration)</li></ul>
173 <p>For explanations, see the <a href="./export-mojo.html"> Documentation of the export-Mojo</a>.</p></div></div>
174 <div class="section">
175 <h2><a name="Configuration-Method-Precedence">Configuration-Method-Precedence</a></h2>
176 <p>The configuration is gathered in a fix order:</p>
177 <ol style="list-style-type: decimal">
178 <li><tt>hibernate.properties</tt></li>
179 <li>maven-properties</li>
180 <li>plugin-configuration</li></ol>
181 <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: <tt>mvn -X hibernate4:export</tt> and be aware, that maven-properties can be overwitten on the command-line, in your <tt>~/.m2/settings.xml</tt> and in a profile.</p>
182 <p>The plugin-configuration comes last and overwrites everything else. That way, you can be sure, that a configuration-value, that is specified in the plugin-configuration will never be overwritten by any other configuration-method.</p>
183 <p>If you realy need to overwrite plugin-configuration-values with maven-properties, you can use maven-properties in the plugin-configuration:</p>
186 <groupId>de.juplo</groupId>
187 <artifactId>hibernate4-maven-plugin</artifactId>
188 <version>${project.version}</version>
192 <goal>export</goal>
196 <configuration>
197 <password>${my-password-property}</password>
198 </configuration>
199 </plugin></pre></div></div>
201 <div class="marginal">
204 <a class="hide" href="#top" title="Show Content">Jump back to the top of the page</a>
205 <h2 class="nav menu">Section-Menu</h2>
207 <li class="m blog"><a href="/blog/" class="m">Blog</a></li>
208 <li class="m projects"><a href="/projects.html" class="m selected">Projects</a></li>
210 <h2 class="nav submenu">
211 <span class="s">Submenu for section</span>
212 <a class="s selected" href="/projects.html">Projects</a>
214 <ul id="submenu" class="s">
216 <a class="s selected" href="./index.html">Hibernate 4 Maven Plugin</a>
217 <ul class="s active">
219 <strong class="s">Configuration Examples</strong>
222 <a href="export-mojo.html" class="s" title="Parameter Documentation">Parameter Documentation</a>
225 <a href="debugging.html" class="s" title="Enable Debug-Output">Enable Debug-Output</a>
228 <a href="force.html" class="s" title="Force Exceution">Force Exceution</a>
231 <a href="pitfalls.html" class="s" title="Known Pitfalls (FAQ)">Known Pitfalls (FAQ)</a>
234 <a href="project-info.html" class="s" title="Project Information">Project Information</a>
237 <a href="project-reports.html" class="s" title="Project Reports">Project Reports</a>
245 <a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy">
246 <img class="poweredBy" alt="Built by Maven" src="./images/logos/maven-feather.png" />
253 <ul id="footerlinks">
254 <li class="f" id="copyright">© <strong>mo</strong> 2013</li>
255 <li class="f"><a class="f" href="/impressum.html">Impressum</a></li>
256 <li class="f about"><a class="f" href="/about.html">About</a></li>
260 <script type="text/javascript"><!--//--><![CDATA[//><!--
261 var _gaq = _gaq || [];
262 _gaq.push(['_setAccount', 'UA-571104-3']);
263 _gaq.push(['_trackPageview']);
265 var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
266 ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
267 var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);