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.
37 So, you should never fire up this configuration on your production
38 system, or your database might be erased!
42 Hence, you should specify a different url for testing like in the
45 <pre class="prettyprint linenums lang-html">
47 <groupId>de.juplo</groupId>
48 <artifactId>hibernate4-maven-plugin</artifactId>
49 <version>${project.version}</version>
53 <goal>export</goal>
58 <url><![CDATA[jdbc:mysql://localhost/test-db]]></url>
59 </configuration>
62 Configuration properties, that are set in the <code>configuration</code>-section
63 of the plugin-configuration cannnot be overwritten elsewere (for details
64 see <a href="#precedence">Configuration-Method-Precedence</a>).
65 You never can overwrite them by accident when specifying a property on
66 the commandline or in your <code>settings.xml</code>.
68 <h2>Configuration through maven-properties</h2>
70 Alternatively, it is possible, to configure the plugin via maven-properties.
71 Each relevant configuration-option has a corresponding maven-property
72 (for a full list see the <a href="./export-mojo.html">Documentation of the export-Mojo</a>).
73 These are named after the
74 <a href="http://docs.jboss.org/hibernate/orm/4.1/manual/en-US/html_single/#configuration-hibernatejdbc">Hibernate JDBC Properties</a>:
77 <li><code>hibernate.connection.driver_class</code></li>
78 <li><code>hibernate.dialect</code></li>
79 <li><code>hibernate.connection.url</code></li>
80 <li><code>hibernate.connection.username</code></li>
81 <li><code>hibernate.connection.password</code></li>
84 So, instead of writing the hibernate-configuration in the properties-file,
85 like above, you could put it in the <code>properties</code>-section of your
89 Thogether with the plugin-definition from above, the following would
90 be a complete configuration (again, the database-url was overwritten in
91 the plugin-configuration, to be sure to have a separate database for
94 <pre class="prettyprint linenums lang-html">
96 <hibernate.connection.driver_class>org.hsqldb.jdbcDriver</hibernate.connection.driver_class>
97 <hibernate.dialect>org.hibernate.dialect.HSQLDialect</hibernate.dialect>
98 <hibernate.connection.url><![CDATA[jdbc:hsqldb:res:org.my.path.production_db]]></hibernate.connection.url>
99 <hibernate.connection.username>sa</hibernate.connection.username>
100 <hibernate.connection.password></hibernate.connection.password>
110 <groupId>de.juplo</groupId>
111 <artifactId>hibernate4-maven-plugin</artifactId>
112 <version>${project.version}</version>
116 <goal>export</goal>
120 <configuration>
121 <url><![CDATA[jdbc:hsqldb:target/db/testdb;shutdown=true]]></url>
122 </configuration>
125 <plugins></pre>
126 <h2>Configuration through the plugin-configuration</h2>
128 A third way for configuring the plugin is the plugin-configuration.
129 The relevant configuration-parameters are:
132 <li><code>driverClassName</code></li>
133 <li><code>hibernateDialect</code></li>
134 <li><code>url</code></li>
135 <li><code>username</code></li>
136 <li><code>password</code></li>
139 The equivalent of the configuration from the last section would look
142 <pre class="prettyprint linenums lang-html">
144 <groupId>de.juplo</groupId>
145 <artifactId>hibernate4-maven-plugin</artifactId>
146 <version>${project.version}</version>
150 <goal>export</goal>
154 <configuration>
155 <driverClassName>org.hsqldb.jdbcDriver</driverClassName>
156 <hibernateDialect>org.hibernate.dialect.HSQLDialect</hibernateDialect>
157 <url><![CDATA[jdbc:hsqldb:target/db/fotos;shutdown=true]]></url>
158 <username>sa</username>
159 <password></password>
160 </configuration>
161 </plugin></pre>
163 The parameter <strong>hibernateProperties</strong> (name of the hibernate-properties-file
164 to use, defaults to <strong>hibernate.properties</strong>) can only be configured through
168 For more explanations, see the
169 <a href="./export-mojo.html">Documentation of the export-Mojo</a>.
171 <h2 id="precedence">Configuration-Method-Precedence</h2>
173 The configuration is gathered in a fix order:
176 <li><code>hibernate.properties</code></li>
177 <li>maven-properties</li>
178 <li>plugin-configuration</li>
181 If you are in doubt about where a configuration-value comes from, run
182 maven with the <a href="./debugging.html">debug-output</a> enabled: <code>mvn -X hibernate4:export</code>
183 and be aware, that maven-properties can be overwitten on the command-line,
184 in your <code>~/.m2/settings.xml</code> and in a profile.
187 The plugin-configuration comes last and overwrites everything else.
188 That way, you can be sure, that a configuration-value, that is
189 specified in the plugin-configuration will never be overwritten by any
190 other configuration-method.
193 If you realy need to overwrite plugin-configuration-values with
194 maven-properties, you can use maven-properties in the plugin-configuration:
196 <pre class="prettyprint linenums lang-html">
198 <groupId>de.juplo</groupId>
199 <artifactId>hibernate4-maven-plugin</artifactId>
200 <version>${project.version}</version>
204 <goal>export</goal>
208 <configuration>
209 <password>${my-password-property}</password>
210 </configuration>
211 </plugin></pre>