Projekt-Dokumentation (Aktueller Stand von juplo.de) hinzugefĆ¼gt
[website] / dist / hibernate4-maven-plugin-1.0.5 / configuration.html
1 <!DOCTYPE html>
2 <!-- Generated by Apache Maven Doxia Site Renderer 1.4 at 2014-11-11 -->
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, skip.html, force.html, pitfalls.html] -->
7 <html>
8   <head>
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     </style>
17     <script src="/js/base.js"></script>
18     <!--[if IE 8]>
19       <link rel="stylesheet" type="text/css" href="/css/ie8.css" />
20       <script src="/js/ie8.js"></script>
21     <![endif]-->
22     <!--[if IE 7]>
23       <script src="/js/ie7.js"></script>
24     <![endif]-->
25     <!--[if lt IE 7]>
26       <script src="/js/ie6.js"></script>
27     <![endif]-->
28         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
29   </head>
30   <body class="menu" onload="prettyPrint()">
31     <div id="page" class="cf">
32       <header id="header">
33         <h1 id="logo"><a href="/" title="Home" class="l">juplo</a></h1>
34         <span id="slogan"><strong>Java</strong> bits from nerds for nerds</span>
35         <hr class="h" />
36       </header>
37       <div id="breadcrumb">
38         <strong class="b title">You are here:</strong>
39         <ol class="b">
40           <li class="b"><a class="b" href="/">Home</a></li>
41           <li class="b"><a class="b" href="/projects.html">Projects</a></li>
42                       <li class="b"><a class="b" href="./index.html">Hibernate 4 Maven Plugin</a></li>
43                         <li class="b"><strong class="b">Configuration Examples</strong></li>
44                   </ol>
45         <a class="hide" href="#navigation">Jump to navigation</a>
46         <hr class="b" />
47       </div>
48       <main class="content cf">
49         <article id="content" class="main">
50           <header><h1>Configuration Examples</h1></header>
51           
52  
53  
54   
55 <div class="section">
56 <h2>Configuration through a hibernate.properties-File<a name="Configuration_through_a_hibernate.properties-File"></a></h2>
57   
58 <p>
59   The most simple way to configure the plugin is, to put all the
60   hibernate-configuration in a <b>hibernate.properties</b>-file on your
61   classpath. Put the file in the <tt>resources</tt>-folder. Maven will put
62   it in the <tt>class</tt>-folder of your webapp, where it will be picked up
63   by this plugin as well as by Hibernate 4.
64   </p>
65   
66 <p>
67   Doing so, the only additionally configuration needed, to activat the plugin
68   is the following entry in the <tt>plugins</tt>-section of your <tt>pom.xml</tt>:
69   </p>
70   
71 <div>
72 <pre class="prettyprint linenums lang-html">
73 &lt;plugin&gt;
74   &lt;groupId&gt;de.juplo&lt;/groupId&gt;
75   &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
76   &lt;version&gt;1.0.5&lt;/version&gt;
77   &lt;executions&gt;
78     &lt;execution&gt;
79       &lt;goals&gt;
80         &lt;goal&gt;export&lt;/goal&gt;
81       &lt;/goals&gt;
82     &lt;/execution&gt;
83   &lt;/executions&gt;
84 &lt;/plugin&gt;</pre></div>
85   
86 <p>
87   But be aware, that in this case the database-url, that is
88   build in the application is the same that is used while testing, where
89   the database is droped and recreated by the plugin.
90   Because of that,
91   <b>
92     you should never fire up this configuration on your production
93     system, or your database might be erased!
94   </b>
95   </p>
96   
97 <p>
98   A better approach is, to specify a different url for testing like in the
99   following snippet:
100   </p>
101   
102 <div>
103 <pre class="prettyprint linenums lang-html">
104 &lt;plugin&gt;
105   &lt;groupId&gt;de.juplo&lt;/groupId&gt;
106   &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
107   &lt;version&gt;1.0.5&lt;/version&gt;
108   &lt;executions&gt;
109     &lt;execution&gt;
110       &lt;goals&gt;
111         &lt;goal&gt;export&lt;/goal&gt;
112       &lt;/goals&gt;
113     &lt;/execution&gt;
114   &lt;/executions&gt;
115   &lt;configuration&gt;
116     &lt;url&gt;&lt;![CDATA[jdbc:mysql://localhost/test-db]]&gt;&lt;/url&gt;
117   &lt;/configuration&gt;
118 &lt;/plugin&gt;</pre></div>
119   
120 <p>
121   Configuration properties, that are set in the <tt>configuration</tt>-section
122   of the plugin-configuration cannnot be overwritten elsewere (for details
123   see <a href="#precedence">Configuration-Method-Precedence</a>).
124   You never can overwrite them by accident when specifying a property on
125   the commandline or in your <tt>settings.xml</tt>.
126   </p>
127   </div>
128 <div class="section">
129 <h2>Configuration through maven-properties<a name="Configuration_through_maven-properties"></a></h2>
130   
131 <p>
132   Alternatively, it is possible, to configure the plugin via maven-properties.
133   Each relevant configuration-option has a corresponding maven-property
134   (for a full list see the <a href="./export-mojo.html">Documentation of the export-Mojo</a>).
135   These are named after the
136   <a class="externalLink" href="http://docs.jboss.org/hibernate/orm/4.1/manual/en-US/html_single/#configuration-hibernatejdbc">Hibernate JDBC Properties</a>:
137   </p>
138   
139 <ul>
140     
141 <li><tt>hibernate.connection.driver_class</tt></li>
142     
143 <li><tt>hibernate.dialect</tt></li>
144     
145 <li><tt>hibernate.connection.url</tt></li>
146     
147 <li><tt>hibernate.connection.username</tt></li>
148     
149 <li><tt>hibernate.connection.password</tt></li>
150   </ul>
151   
152 <p>
153   So, instead of writing the hibernate-configuration in the properties-file,
154   like above, you could put it in the <tt>properties</tt>-section of your
155   <tt>pom.xml</tt>.
156   </p>
157   
158 <p>
159   Thogether with the plugin-definition from above, the following would
160   be a complete configuration (again, the database-url was overwritten in
161   the plugin-configuration, to be sure to have a separate database for
162   testing):
163   </p>
164   
165 <div>
166 <pre class="prettyprint linenums lang-html">
167 &lt;properties&gt;
168   &lt;hibernate.connection.driver_class&gt;org.hsqldb.jdbcDriver&lt;/hibernate.connection.driver_class&gt;
169   &lt;hibernate.dialect&gt;org.hibernate.dialect.HSQLDialect&lt;/hibernate.dialect&gt;
170   &lt;hibernate.connection.url&gt;&lt;![CDATA[jdbc:hsqldb:res:org.my.path.production_db]]&gt;&lt;/hibernate.connection.url&gt;
171   &lt;hibernate.connection.username&gt;sa&lt;/hibernate.connection.username&gt;
172   &lt;hibernate.connection.password&gt;&lt;/hibernate.connection.password&gt;
173 &lt;/properties&gt;
174
175 ...
176
177 &lt;plugins&gt;
178
179   ...
180
181   &lt;plugin&gt;
182     &lt;groupId&gt;de.juplo&lt;/groupId&gt;
183     &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
184     &lt;version&gt;1.0.5&lt;/version&gt;
185     &lt;executions&gt;
186       &lt;execution&gt;
187         &lt;goals&gt;
188           &lt;goal&gt;export&lt;/goal&gt;
189         &lt;/goals&gt;
190       &lt;/execution&gt;
191     &lt;/executions&gt;
192     &lt;configuration&gt;
193       &lt;url&gt;&lt;![CDATA[jdbc:hsqldb:target/db/testdb;shutdown=true]]&gt;&lt;/url&gt;
194     &lt;/configuration&gt;
195   &lt;/plugin&gt;
196
197 &lt;plugins&gt;</pre></div>
198   </div>
199 <div class="section">
200 <h2>Configuration through the plugin-configuration<a name="Configuration_through_the_plugin-configuration"></a></h2>
201   
202 <p>
203   A third way for configuring the plugin is the plugin-configuration.
204   The relevant configuration-parameters are:
205   </p>
206   
207 <ul>
208     
209 <li><tt>driverClassName</tt></li>
210     
211 <li><tt>hibernateDialect</tt></li>
212     
213 <li><tt>url</tt></li>
214     
215 <li><tt>username</tt></li>
216     
217 <li><tt>password</tt></li>
218   </ul>
219   
220 <p>
221   The equivalent of the configuration from the last section would look
222   like this:
223   </p>
224   
225 <div>
226 <pre class="prettyprint linenums lang-html">
227 &lt;plugin&gt;
228   &lt;groupId&gt;de.juplo&lt;/groupId&gt;
229   &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
230   &lt;version&gt;1.0.5&lt;/version&gt;
231   &lt;executions&gt;
232     &lt;execution&gt;
233       &lt;goals&gt;
234         &lt;goal&gt;export&lt;/goal&gt;
235       &lt;/goals&gt;
236     &lt;/execution&gt;
237   &lt;/executions&gt;
238   &lt;configuration&gt;
239     &lt;driverClassName&gt;org.hsqldb.jdbcDriver&lt;/driverClassName&gt;
240     &lt;hibernateDialect&gt;org.hibernate.dialect.HSQLDialect&lt;/hibernateDialect&gt;
241     &lt;url&gt;&lt;![CDATA[jdbc:hsqldb:target/db/fotos;shutdown=true]]&gt;&lt;/url&gt;
242     &lt;username&gt;sa&lt;/username&gt;
243     &lt;password&gt;&lt;/password&gt;
244   &lt;/configuration&gt;
245 &lt;/plugin&gt;</pre></div>
246   
247 <p>
248   The parameter <b>hibernateProperties</b> (name of the hibernate-properties-file
249   to use, defaults to <b>hibernate.properties</b>) can only be configured through
250   this approach.
251   </p>
252   
253 <p>
254   For more explanations, see the
255   <a href="./export-mojo.html">Documentation of the export-Mojo</a>.
256   </p>
257   </div>
258 <div class="section" id="precedence">
259 <h2 id="precedence">Configuration-Method-Precedence</h2>
260   
261 <p>
262   The configuration is gathered in a fix order:
263   </p>
264   
265 <ol style="list-style-type: decimal">
266     
267 <li><tt>hibernate.properties</tt></li>
268     
269 <li>maven-properties</li>
270     
271 <li>plugin-configuration</li>
272   </ol>
273   
274 <p>
275   If you are in doubt about where a configuration-value comes from, run
276   maven with the <a href="./debugging.html">debug-output</a> enabled: <tt>mvn -X hibernate4:export</tt>
277   and be aware, that maven-properties can be overwitten on the command-line,
278   in your <tt>~/.m2/settings.xml</tt> and in a profile.
279   </p>
280   
281 <p>
282   The plugin-configuration comes last and overwrites everything else.
283   That way, you can be sure, that a configuration-value, that is
284   specified in the plugin-configuration will never be overwritten by any
285   other configuration-method.
286   </p>
287   
288 <p>
289   If you need to overwrite plugin-configuration-values with
290   maven-properties, you can use maven-properties in the plugin-configuration:
291   </p>
292   
293 <div>
294 <pre class="prettyprint linenums lang-html">
295 &lt;plugin&gt;
296   &lt;groupId&gt;de.juplo&lt;/groupId&gt;
297   &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
298   &lt;version&gt;1.0.5&lt;/version&gt;
299   &lt;executions&gt;
300     &lt;execution&gt;
301       &lt;goals&gt;
302         &lt;goal&gt;export&lt;/goal&gt;
303       &lt;/goals&gt;
304     &lt;/execution&gt;
305   &lt;/executions&gt;
306   &lt;configuration&gt;
307     &lt;password&gt;${my-password-property}&lt;/password&gt;
308   &lt;/configuration&gt;
309 &lt;/plugin&gt;</pre></div>
310  </div>
311
312         </article>
313         <div class="marginal">
314           <nav id="nav">
315             <hr class="n" />
316             <a id="navigation"></a>
317             <a class="hide" href="#top" title="Show Content">Jump back to the top of the page</a>
318             <h2 class="nav menu">Section-Menu</h2>
319             <ul id="menu">
320               <li class="m blog"><a href="/blog/" class="m">Blog</a></li>
321               <li class="m projects"><a href="/projects.html" class="m selected">Projects</a></li>
322               <li class="m about"><a href="/about.html" class="m">About</a></li>
323             </ul>
324             <h2 class="nav submenu">
325               <span class="s">Submenu for section</span>
326               <a class="s selected" href="/projects.html">Projects</a>
327             </h2>
328             <ul id="submenu" class="s">
329                                                               <li class="s sub">
330                                           <a class="s selected" href="./index.html">Hibernate 4 Maven Plugin</a>
331                                         <ul class="s active">
332                                                                                                                                                                                                                                                                 <li class="s">
333               <strong class="s">Configuration Examples</strong>
334                 </li>
335                                                                                                                   <li class="s">
336                     <a href="export-mojo.html" class="s" title="Parameter Documentation">Parameter Documentation</a>
337                 </li>
338                                                                                                                   <li class="s">
339                     <a href="debugging.html" class="s" title="Enable Debug-Output">Enable Debug-Output</a>
340                 </li>
341                                                                                                                   <li class="s">
342                     <a href="skip.html" class="s" title="Skipping Execution">Skipping Execution</a>
343                 </li>
344                                                                                                                   <li class="s">
345                     <a href="force.html" class="s" title="Force Exceution">Force Exceution</a>
346                 </li>
347                                                                                                                   <li class="s">
348                     <a href="pitfalls.html" class="s" title="Known Pitfalls (FAQ)">Known Pitfalls (FAQ)</a>
349                 </li>
350                                                                                                                                                                                                                                                                                                                                                   <li class="s sub">
351                     <a href="project-info.html" class="s" title="Project Information">Project Information</a>
352                 </li>
353                                                                                                                                                                                                   <li class="s sub">
354                     <a href="project-reports.html" class="s" title="Project Reports">Project Reports</a>
355                 </li>
356                                                                                               </ul>
357                   </li>
358                                           </ul>
359             <hr class="n" />
360           </nav>
361           <aside class="m">
362             <a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy">
363               <img class="poweredBy" alt="Built by Maven" src="./images/logos/maven-feather.png" />
364             </a>
365           </aside>
366         </div>
367       </main>
368       <footer id="footer">
369         <hr class="f" />
370         <ul id="footerlinks">
371           <li class="f" id="copyright">&#xa9; <strong>mo</strong>             2014
372       </li>
373           <li class="f"><a class="f" href="/impressum.html">Impressum</a></li>
374           <li class="f about"><a class="f" href="/about.html">About</a></li>
375         </ul>
376       </footer>
377     </div>
378         <script type="text/javascript"><!--//--><![CDATA[//><!--
379       var _gaq = _gaq || [];
380       _gaq.push(['_setAccount', 'UA-571104-3']);
381       _gaq.push(['_trackPageview']);
382       (function() {
383         var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
384         ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
385         var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
386       })();
387     //--><!]]>
388     </script>
389       </body>
390 </html>