[maven-release-plugin] prepare for next development iteration
[hibernate4-maven-plugin] / src / site / xhtml / configuration.xhtml
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">
3  <head>
4  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5  </head>
6  <body>
7   <h2>Configuration through a hibernate.properties-File</h2>
8   <p>
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.
14   </p>
15   <p>
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>:
18   </p>
19   <pre class="prettyprint linenums lang-html">
20 &lt;plugin&gt;
21   &lt;groupId&gt;de.juplo&lt;/groupId&gt;
22   &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
23   &lt;version&gt;${project.version}&lt;/version&gt;
24   &lt;executions&gt;
25     &lt;execution&gt;
26       &lt;goals&gt;
27         &lt;goal&gt;export&lt;/goal&gt;
28       &lt;/goals&gt;
29     &lt;/execution&gt;
30   &lt;/executions&gt;
31 &lt;/plugin&gt;</pre>
32   <p>
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.
36   Because of that,
37   <strong>
38     you should never fire up this configuration on your production
39     system, or your database might be erased!
40   </strong>
41   </p>
42   <p>
43   A better approach is, to specify a different url for testing like in the
44   following snippet:
45   </p>
46   <pre class="prettyprint linenums lang-html">
47 &lt;plugin&gt;
48   &lt;groupId&gt;de.juplo&lt;/groupId&gt;
49   &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
50   &lt;version&gt;${project.version}&lt;/version&gt;
51   &lt;executions&gt;
52     &lt;execution&gt;
53       &lt;goals&gt;
54         &lt;goal&gt;export&lt;/goal&gt;
55       &lt;/goals&gt;
56     &lt;/execution&gt;
57   &lt;/executions&gt;
58   &lt;configuration&gt;
59     &lt;url&gt;&lt;![CDATA[jdbc:mysql://localhost/test-db]]&gt;&lt;/url&gt;
60   &lt;/configuration&gt;
61 &lt;/plugin&gt;</pre>
62   <p>
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>.
68   </p>
69   <h2>Configuration through maven-properties</h2>
70   <p>
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>:
76   </p>
77   <ul>
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>
83   </ul>
84   <p>
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
87   <code>pom.xml</code>.
88   </p>
89   <p>
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
93   testing):
94   </p>
95   <pre class="prettyprint linenums lang-html">
96 &lt;properties&gt;
97   &lt;hibernate.connection.driver_class&gt;org.hsqldb.jdbcDriver&lt;/hibernate.connection.driver_class&gt;
98   &lt;hibernate.dialect&gt;org.hibernate.dialect.HSQLDialect&lt;/hibernate.dialect&gt;
99   &lt;hibernate.connection.url&gt;&lt;![CDATA[jdbc:hsqldb:res:org.my.path.production_db]]&gt;&lt;/hibernate.connection.url&gt;
100   &lt;hibernate.connection.username&gt;sa&lt;/hibernate.connection.username&gt;
101   &lt;hibernate.connection.password&gt;&lt;/hibernate.connection.password&gt;
102 &lt;/properties&gt;
103
104 ...
105
106 &lt;plugins&gt;
107
108   ...
109
110   &lt;plugin&gt;
111     &lt;groupId&gt;de.juplo&lt;/groupId&gt;
112     &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
113     &lt;version&gt;${project.version}&lt;/version&gt;
114     &lt;executions&gt;
115       &lt;execution&gt;
116         &lt;goals&gt;
117           &lt;goal&gt;export&lt;/goal&gt;
118         &lt;/goals&gt;
119       &lt;/execution&gt;
120     &lt;/executions&gt;
121     &lt;configuration&gt;
122       &lt;url&gt;&lt;![CDATA[jdbc:hsqldb:target/db/testdb;shutdown=true]]&gt;&lt;/url&gt;
123     &lt;/configuration&gt;
124   &lt;/plugin&gt;
125
126 &lt;plugins&gt;</pre>
127   <h2>Configuration through the plugin-configuration</h2>
128   <p>
129   A third way for configuring the plugin is the plugin-configuration.
130   The relevant configuration-parameters are:
131   </p>
132   <ul>
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>
138   </ul>
139   <p>
140   The equivalent of the configuration from the last section would look
141   like this:
142   </p>
143   <pre class="prettyprint linenums lang-html">
144 &lt;plugin&gt;
145   &lt;groupId&gt;de.juplo&lt;/groupId&gt;
146   &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
147   &lt;version&gt;${project.version}&lt;/version&gt;
148   &lt;executions&gt;
149     &lt;execution&gt;
150       &lt;goals&gt;
151         &lt;goal&gt;export&lt;/goal&gt;
152       &lt;/goals&gt;
153     &lt;/execution&gt;
154   &lt;/executions&gt;
155   &lt;configuration&gt;
156     &lt;driverClassName&gt;org.hsqldb.jdbcDriver&lt;/driverClassName&gt;
157     &lt;hibernateDialect&gt;org.hibernate.dialect.HSQLDialect&lt;/hibernateDialect&gt;
158     &lt;url&gt;&lt;![CDATA[jdbc:hsqldb:target/db/fotos;shutdown=true]]&gt;&lt;/url&gt;
159     &lt;username&gt;sa&lt;/username&gt;
160     &lt;password&gt;&lt;/password&gt;
161   &lt;/configuration&gt;
162 &lt;/plugin&gt;</pre>
163   <p>
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
166   this approach.
167   </p>
168   <p>
169   For more explanations, see the
170   <a href="./export-mojo.html">Documentation of the export-Mojo</a>.
171   </p>
172   <h2 id="precedence">Configuration-Method-Precedence</h2>
173   <p>
174   The configuration is gathered in a fix order:
175   </p>
176   <ol>
177     <li><code>hibernate.properties</code></li>
178     <li>maven-properties</li>
179     <li>plugin-configuration</li>
180   </ol>
181   <p>
182   If you are in doubt about where a configuration-value comes from, run
183   maven with the <a href="./debugging.html">debug-output</a> enabled: <code>mvn -X hibernate4:export</code>
184   and be aware, that maven-properties can be overwitten on the command-line,
185   in your <code>~/.m2/settings.xml</code> and in a profile.
186   </p>
187   <p>
188   The plugin-configuration comes last and overwrites everything else.
189   That way, you can be sure, that a configuration-value, that is
190   specified in the plugin-configuration will never be overwritten by any
191   other configuration-method.
192   </p>
193   <p>
194   If you need to overwrite plugin-configuration-values with
195   maven-properties, you can use maven-properties in the plugin-configuration:
196   </p>
197   <pre class="prettyprint linenums lang-html">
198 &lt;plugin&gt;
199   &lt;groupId&gt;de.juplo&lt;/groupId&gt;
200   &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
201   &lt;version&gt;${project.version}&lt;/version&gt;
202   &lt;executions&gt;
203     &lt;execution&gt;
204       &lt;goals&gt;
205         &lt;goal&gt;export&lt;/goal&gt;
206       &lt;/goals&gt;
207     &lt;/execution&gt;
208   &lt;/executions&gt;
209   &lt;configuration&gt;
210     &lt;password&gt;${my-password-property}&lt;/password&gt;
211   &lt;/configuration&gt;
212 &lt;/plugin&gt;</pre>
213  </body>
214 </html>