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 hibernate.properties-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>-file on your
11 classpath. Put the file in the <code>resources</code>-folder. Maven will put
12 it in the <code>class</code>-folder of your webapp, where it will be picked up
13 by this plugin as well as by Hibernate 4.
16 Doing so, the only additionally configuration needed, to activat the plugin
17 is the following entry in the <code>plugins</code>-section of your <code>pom.xml</code>:
19 <pre class="prettyprint linenums lang-html">
21 <groupId>de.juplo</groupId>
22 <artifactId>hibernate4-maven-plugin</artifactId>
23 <version>${project.version}</version>
27 <goal>export</goal>
33 But be aware, that in this case the database-url, that is
34 build in the application is the same that is used while testing, where
35 the database is droped and recreated by the plugin.
38 you should never fire up this configuration on your production
39 system, or your database might be erased!
43 A better approach is, to specify a different url for testing like in the
46 <pre class="prettyprint linenums lang-html">
48 <groupId>de.juplo</groupId>
49 <artifactId>hibernate4-maven-plugin</artifactId>
50 <version>${project.version}</version>
54 <goal>export</goal>
59 <url><![CDATA[jdbc:mysql://localhost/test-db]]></url>
60 </configuration>
63 Configuration properties, that are set in the <code>configuration</code>-section
64 of the plugin-configuration cannnot be overwritten elsewere (for details
65 see <a href="#precedence">Configuration-Method-Precedence</a>).
66 You never can overwrite them by accident when specifying a property on
67 the commandline or in your <code>settings.xml</code>.
69 <h2>Configuration through maven-properties</h2>
71 Alternatively, it is possible, to configure the plugin via maven-properties.
72 Each relevant configuration-option has a corresponding maven-property
73 (for a full list see the <a href="./export-mojo.html">Documentation of the export-Mojo</a>).
74 These are named after the
75 <a href="http://docs.jboss.org/hibernate/orm/4.1/manual/en-US/html_single/#configuration-hibernatejdbc">Hibernate JDBC Properties</a>:
78 <li><code>hibernate.connection.driver_class</code></li>
79 <li><code>hibernate.dialect</code></li>
80 <li><code>hibernate.connection.url</code></li>
81 <li><code>hibernate.connection.username</code></li>
82 <li><code>hibernate.connection.password</code></li>
85 So, instead of writing the hibernate-configuration in the properties-file,
86 like above, you could put it in the <code>properties</code>-section of your
90 Thogether with the plugin-definition from above, the following would
91 be a complete configuration (again, the database-url was overwritten in
92 the plugin-configuration, to be sure to have a separate database for
95 <pre class="prettyprint linenums lang-html">
97 <hibernate.connection.driver_class>org.hsqldb.jdbcDriver</hibernate.connection.driver_class>
98 <hibernate.dialect>org.hibernate.dialect.HSQLDialect</hibernate.dialect>
99 <hibernate.connection.url><![CDATA[jdbc:hsqldb:res:org.my.path.production_db]]></hibernate.connection.url>
100 <hibernate.connection.username>sa</hibernate.connection.username>
101 <hibernate.connection.password></hibernate.connection.password>
111 <groupId>de.juplo</groupId>
112 <artifactId>hibernate4-maven-plugin</artifactId>
113 <version>${project.version}</version>
117 <goal>export</goal>
121 <configuration>
122 <url><![CDATA[jdbc:hsqldb:target/db/testdb;shutdown=true]]></url>
123 </configuration>
126 <plugins></pre>
127 <h2>Configuration through the plugin-configuration</h2>
129 A third way for configuring the plugin is the plugin-configuration.
130 The relevant configuration-parameters are:
133 <li><code>driverClassName</code></li>
134 <li><code>hibernateDialect</code></li>
135 <li><code>url</code></li>
136 <li><code>username</code></li>
137 <li><code>password</code></li>
140 The equivalent of the configuration from the last section would look
143 <pre class="prettyprint linenums lang-html">
145 <groupId>de.juplo</groupId>
146 <artifactId>hibernate4-maven-plugin</artifactId>
147 <version>${project.version}</version>
151 <goal>export</goal>
155 <configuration>
156 <driverClassName>org.hsqldb.jdbcDriver</driverClassName>
157 <hibernateDialect>org.hibernate.dialect.HSQLDialect</hibernateDialect>
158 <url><![CDATA[jdbc:hsqldb:target/db/fotos;shutdown=true]]></url>
159 <username>sa</username>
160 <password></password>
161 </configuration>
162 </plugin></pre>
164 The parameter <strong>hibernateProperties</strong> (name of the hibernate-properties-file
165 to use, defaults to <strong>hibernate.properties</strong>) can only be configured through
169 For more explanations, see the
170 <a href="./export-mojo.html">Documentation of the export-Mojo</a>.
172 <h2 id="precedence">Configuration-Method-Precedence</h2>
174 The configuration is gathered in a fix order:
177 <li><code>hibernate.properties</code></li>
178 <li><code>hibernate.cfg.xml</code></li>
179 <li><code>persistence.xml</code></li>
180 <li>maven-properties</li>
181 <li>plugin-configuration</li>
184 If you are in doubt about where a configuration-value comes from, run
185 maven with the <a href="./debugging.html">debug-output</a> enabled: <code>mvn -X hibernate4:export</code>
186 and be aware, that maven-properties can be overwitten on the command-line,
187 in your <code>~/.m2/settings.xml</code> and in a profile.
190 The plugin-configuration comes last and overwrites everything else.
191 That way, you can be sure, that a configuration-value, that is
192 specified in the plugin-configuration will never be overwritten by any
193 other configuration-method.
196 If you need to overwrite plugin-configuration-values with
197 maven-properties, you can use maven-properties in the plugin-configuration:
199 <pre class="prettyprint linenums lang-html">
201 <groupId>de.juplo</groupId>
202 <artifactId>hibernate4-maven-plugin</artifactId>
203 <version>${project.version}</version>
207 <goal>export</goal>
211 <configuration>
212 <password>${my-password-property}</password>
213 </configuration>
214 </plugin></pre>