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 hibernate.properties-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>-file on your
12 classpath. Put the file in the <code>resources</code>-folder. Maven will put
13 it in the <code>class</code>-folder of your webapp, where it will be picked up
14 by this plugin as well as by Hibernate 4.
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>hibernate4-maven-plugin</artifactId>
24 <version>${project.version}</version>
28 <goal>export</goal>
34 But be aware, that in this case the database-url, that is
35 build in the application is the same that is used while testing, where
36 the database is droped and recreated by the plugin.
39 you should never fire up this configuration on your production
40 system, or your database might be erased!
44 A better approach is, to specify a different url for testing like in the
47 <pre class="prettyprint linenums lang-html">
49 <groupId>de.juplo</groupId>
50 <artifactId>hibernate4-maven-plugin</artifactId>
51 <version>${project.version}</version>
55 <goal>export</goal>
60 <url><![CDATA[jdbc:mysql://localhost/test-db]]></url>
61 </configuration>
64 Configuration properties, that are set in the <code>configuration</code>-section
65 of the plugin-configuration cannnot be overwritten elsewere (for details
66 see <a href="#precedence">Configuration-Method-Precedence</a>).
67 You never can overwrite them by accident when specifying a property on
68 the commandline or in your <code>settings.xml</code>.
70 <h2>Configuration through maven-properties</h2>
72 Alternatively, it is possible, to configure the plugin via maven-properties.
73 Each relevant configuration-option has a corresponding maven-property
74 (for a full list see the <a href="./export-mojo.html">Documentation of the export-Mojo</a>).
75 These are named after the
76 <a href="http://docs.jboss.org/hibernate/orm/4.1/manual/en-US/html_single/#configuration-hibernatejdbc">Hibernate JDBC Properties</a>:
79 <li><code>hibernate.connection.driver_class</code></li>
80 <li><code>hibernate.dialect</code></li>
81 <li><code>hibernate.connection.url</code></li>
82 <li><code>hibernate.connection.username</code></li>
83 <li><code>hibernate.connection.password</code></li>
86 So, instead of writing the hibernate-configuration in the properties-file,
87 like above, you could put it in the <code>properties</code>-section of your
91 Thogether with the plugin-definition from above, the following would
92 be a complete configuration (again, the database-url was overwritten in
93 the plugin-configuration, to be sure to have a separate database for
96 <pre class="prettyprint linenums lang-html">
98 <hibernate.connection.driver_class>org.hsqldb.jdbcDriver</hibernate.connection.driver_class>
99 <hibernate.dialect>org.hibernate.dialect.HSQLDialect</hibernate.dialect>
100 <hibernate.connection.url><![CDATA[jdbc:hsqldb:res:org.my.path.production_db]]></hibernate.connection.url>
101 <hibernate.connection.username>sa</hibernate.connection.username>
102 <hibernate.connection.password></hibernate.connection.password>
112 <groupId>de.juplo</groupId>
113 <artifactId>hibernate4-maven-plugin</artifactId>
114 <version>${project.version}</version>
118 <goal>export</goal>
122 <configuration>
123 <url><![CDATA[jdbc:hsqldb:target/db/testdb;shutdown=true]]></url>
124 </configuration>
127 <plugins></pre>
128 <h2>Configuration through the plugin-configuration</h2>
130 A third way for configuring the plugin is the plugin-configuration.
131 The relevant configuration-parameters are:
134 <li><code>driverClassName</code></li>
135 <li><code>hibernateDialect</code></li>
136 <li><code>url</code></li>
137 <li><code>username</code></li>
138 <li><code>password</code></li>
141 The equivalent of the configuration from the last section would look
144 <pre class="prettyprint linenums lang-html">
146 <groupId>de.juplo</groupId>
147 <artifactId>hibernate4-maven-plugin</artifactId>
148 <version>${project.version}</version>
152 <goal>export</goal>
156 <configuration>
157 <driverClassName>org.hsqldb.jdbcDriver</driverClassName>
158 <hibernateDialect>org.hibernate.dialect.HSQLDialect</hibernateDialect>
159 <url><![CDATA[jdbc:hsqldb:target/db/fotos;shutdown=true]]></url>
160 <username>sa</username>
161 <password></password>
162 </configuration>
163 </plugin></pre>
165 The parameter <strong>hibernateProperties</strong> (name of the hibernate-properties-file
166 to use, defaults to <strong>hibernate.properties</strong>) can only be configured through
170 For more explanations, see the
171 <a href="./export-mojo.html">Documentation of the export-Mojo</a>.
173 <h2 id="precedence">Configuration-Method-Precedence</h2>
175 The configuration is gathered in a fix order:
178 <li><code>hibernate.properties</code></li>
179 <li>maven-properties</li>
180 <li>plugin-configuration</li>
183 If you are in doubt about where a configuration-value comes from, run
184 maven with the <a href="./debugging.html">debug-output</a> enabled: <code>mvn -X hibernate4:export</code>
185 and be aware, that maven-properties can be overwitten on the command-line,
186 in your <code>~/.m2/settings.xml</code> and in a profile.
189 The plugin-configuration comes last and overwrites everything else.
190 That way, you can be sure, that a configuration-value, that is
191 specified in the plugin-configuration will never be overwritten by any
192 other configuration-method.
195 If you need to overwrite plugin-configuration-values with
196 maven-properties, you can use maven-properties in the plugin-configuration:
198 <pre class="prettyprint linenums lang-html">
200 <groupId>de.juplo</groupId>
201 <artifactId>hibernate4-maven-plugin</artifactId>
202 <version>${project.version}</version>
206 <goal>export</goal>
210 <configuration>
211 <password>${my-password-property}</password>
212 </configuration>
213 </plugin></pre>