Projekt-Dokumentation (Aktueller Stand von juplo.de) hinzugefügt
[website] / dist / hibernate4-maven-plugin-1.0.2 / configuration.html
1 <!DOCTYPE html>
2 <!-- Generated by Apache Maven Doxia Site Renderer 1.4 at 2014-04-29 -->
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, 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       @import '/css/print.css' print;
17     </style>
18     <script src="/js/base.js"></script>
19     <!--[if IE 8]>
20       <link rel="stylesheet" type="text/css" href="/css/ie8.css" />
21       <script src="/js/ie8.js"></script>
22     <![endif]-->
23     <!--[if IE 7]>
24       <script src="/js/ie7.js"></script>
25     <![endif]-->
26     <!--[if lt IE 7]>
27       <script src="/js/ie6.js"></script>
28     <![endif]-->
29     <meta name="Date-Revision-yyyymmdd" content="20140429" />
30     <meta http-equiv="Content-Language" content="en" />
31         
32   </head>
33   <body id="top" class="menu" onload="prettyPrint()">
34     <div id="page" class="cf">
35       <header id="header">
36         <h1 id="logo"><a href="/" title="Home" class="l">juplo</a></h1>
37         <span id="slogan"><strong>Java</strong> bits from nerds for nerds</span>
38         <hr class="h" />
39       </header>
40       <div id="breadcrumb">
41         <strong class="b title">You are here:</strong>
42         <ol class="b">
43           <li class="b"><a class="b" href="/">Home</a></li>
44           <li class="b"><a class="b" href="/projects.html">Projects</a></li>
45                       <li class="b"><a class="b" href="./index.html">Hibernate 4 Maven Plugin</a </li>
46                         <li class="b"><strong class="b">Configuration Examples</strong></li>
47                   </ol>
48         <a class="hide" href="#nav" title="Show navigation menu">Jump to navigation</a>
49         <hr class="b" />
50       </div>
51       <main class="content cf">
52         <section id="content" class="main">
53           <h1>Hibernate 4 Maven Plugin - Configuration Examples</h1>
54           <div class="section">
55 <h2>Configuration Examples<a name="Configuration_Examples"></a></h2>
56 <div class="section">
57 <h3>Configuration through a hibernate.properties-File<a name="Configuration_through_a_hibernate.properties-File"></a></h3>
58 <p>The most simple way to configure the plugin is, to put all the hibernate-configuration in a <b>hibernate.properties</b>-file on your classpath. Put the file in the <tt>resources</tt>-folder. Maven will put it in the <tt>class</tt>-folder of your webapp, where it will be picked up by this plugin as well as by Hibernate 4.</p>
59 <p>Doing so, the only additionally configuration needed, to activat the plugin is the following entry in the <tt>plugins</tt>-section of your <tt>pom.xml</tt>:</p>
60 <div>
61 <pre>&lt;plugin&gt;
62   &lt;groupId&gt;de.juplo&lt;/groupId&gt;
63   &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
64   &lt;version&gt;${project.version}&lt;/version&gt;
65   &lt;executions&gt;
66     &lt;execution&gt;
67       &lt;goals&gt;
68         &lt;goal&gt;export&lt;/goal&gt;
69       &lt;/goals&gt;
70     &lt;/execution&gt;
71   &lt;/executions&gt;
72 &lt;/plugin&gt;</pre></div>
73 <p>But be aware, that in this case the database-url, that is build in the application is the same that is used while testing, where the database is droped and recreated by the plugin. <tt>So, you should never fire up this configuration on your production system, or your database might be erased!</tt></p>
74 <p>Hence, you should specify a different url for testing like in the following snippet:</p>
75 <div>
76 <pre>&lt;plugin&gt;
77   &lt;groupId&gt;de.juplo&lt;/groupId&gt;
78   &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
79   &lt;version&gt;${project.version}&lt;/version&gt;
80   &lt;executions&gt;
81     &lt;execution&gt;
82       &lt;goals&gt;
83         &lt;goal&gt;export&lt;/goal&gt;
84       &lt;/goals&gt;
85     &lt;/execution&gt;
86   &lt;/executions&gt;
87   &lt;configuration&gt;
88     &lt;url&gt;&lt;![CDATA[jdbc:mysql://localhost/test-db]]&gt;&lt;/url&gt;
89   &lt;/configuration&gt;
90 &lt;/plugin&gt;</pre></div>
91 <p>Configuration properties, that are set in the <tt>configuration</tt>-section of the plugin-configuration cannnot be overwritten elsewere (for details see <a href="#Configuration-Method-Precedence">Configuration-Method-Precedence</a>). You never can overwrite them by accident when specifying a property on the commandline or in your <tt>settings.xml</tt>.</p></div>
92 <div class="section">
93 <h3>Configuration through maven-properties<a name="Configuration_through_maven-properties"></a></h3>
94 <p>Alternatively, it is possible, to configure the plugin via maven-properties. Each relevant configuration-option has a corresponding maven-property (for a full list see the <a href="./export-mojo.html"> Documentation of the export-Mojo</a>). These are named after the <a class="externalLink" href="http://docs.jboss.org/hibernate/orm/4.1/manual/en-US/html_single/#configuration-hibernatejdbc"> Hibernate JDBC Properties</a>:</p>
95 <ul>
96 <li><tt>hibernate.connection.driver_class</tt></li>
97 <li><tt>hibernate.dialect</tt></li>
98 <li><tt>hibernate.connection.url</tt></li>
99 <li><tt>hibernate.connection.username</tt></li>
100 <li><tt>hibernate.connection.password</tt></li></ul>
101 <p>So, instead of writing the hibernate-configuration in the properties-file, like above, you could put it in the <tt>properties</tt>-section of your <tt>pom.xml</tt>.</p>
102 <p>Thogether with the plugin-definition from above, the following would be a complete configuration (again, the database-url was overwritten in the plugin-configuration, to be sure to have a separate database for testing):</p>
103 <div>
104 <pre>&lt;properties&gt;
105   &lt;hibernate.connection.driver_class&gt;org.hsqldb.jdbcDriver&lt;/hibernate.connection.driver_class&gt;
106   &lt;hibernate.dialect&gt;org.hibernate.dialect.HSQLDialect&lt;/hibernate.dialect&gt;
107   &lt;hibernate.connection.url&gt;&lt;![CDATA[jdbc:hsqldb:res:org.my.path.production_db]]&gt;&lt;/hibernate.connection.url&gt;
108   &lt;hibernate.connection.username&gt;sa&lt;/hibernate.connection.username&gt;
109   &lt;hibernate.connection.password&gt;&lt;/hibernate.connection.password&gt;
110 &lt;/properties&gt;
111
112 ...
113
114 &lt;plugins&gt;
115
116   ...
117
118   &lt;plugin&gt;
119     &lt;groupId&gt;de.juplo&lt;/groupId&gt;
120     &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
121     &lt;version&gt;${project.version}&lt;/version&gt;
122     &lt;executions&gt;
123       &lt;execution&gt;
124         &lt;goals&gt;
125           &lt;goal&gt;export&lt;/goal&gt;
126         &lt;/goals&gt;
127       &lt;/execution&gt;
128     &lt;/executions&gt;
129     &lt;configuration&gt;
130       &lt;url&gt;&lt;![CDATA[jdbc:hsqldb:target/db/testdb;shutdown=true]]&gt;&lt;/url&gt;
131     &lt;/configuration&gt;
132   &lt;/plugin&gt;
133
134 &lt;plugins&gt;</pre></div></div>
135 <div class="section">
136 <h3>Configuration through the plugin-configuration<a name="Configuration_through_the_plugin-configuration"></a></h3>
137 <p>A third way for configuring the plugin is the plugin-configuration. The relevant configuration-parameters are:</p>
138 <ul>
139 <li><tt>driverClassName</tt></li>
140 <li><tt>hibernateDialect</tt></li>
141 <li><tt>url</tt></li>
142 <li><tt>username</tt></li>
143 <li><tt>password</tt></li></ul>
144 <p>The equivalent of the configuration from the last section would look like this:</p>
145 <div>
146 <pre>&lt;plugin&gt;
147   &lt;groupId&gt;de.juplo&lt;/groupId&gt;
148   &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
149   &lt;version&gt;${project.version}&lt;/version&gt;
150   &lt;executions&gt;
151     &lt;execution&gt;
152       &lt;goals&gt;
153         &lt;goal&gt;export&lt;/goal&gt;
154       &lt;/goals&gt;
155     &lt;/execution&gt;
156   &lt;/executions&gt;
157   &lt;configuration&gt;
158     &lt;driverClassName&gt;org.hsqldb.jdbcDriver&lt;/driverClassName&gt;
159     &lt;hibernateDialect&gt;org.hibernate.dialect.HSQLDialect&lt;/hibernateDialect&gt;
160     &lt;url&gt;&lt;![CDATA[jdbc:hsqldb:target/db/fotos;shutdown=true]]&gt;&lt;/url&gt;
161     &lt;username&gt;sa&lt;/username&gt;
162     &lt;password&gt;&lt;/password&gt;
163   &lt;/configuration&gt;
164 &lt;/plugin&gt;</pre></div>
165 <p>There are some seldom used parameters, that can only be configured throug this method:</p>
166 <ul>
167 <li><b>delimiter</b> the delimiter used in the generated sql-script</li>
168 <li><b>format</b> wether the generated sql-script is formatted, or not</li>
169 <li><b>hibernateProperties</b> name of the hibernate-properties-file</li>
170 <li><b>outputFile</b> name of the generated sql-script</li>
171 <li><b>target</b> create database or generate sql-script or both</li>
172 <li><b>type</b> create or drop the database or do both or nothing (just validate the annotation-configuration)</li></ul>
173 <p>For explanations, see the <a href="./export-mojo.html"> Documentation of the export-Mojo</a>.</p></div></div>
174 <div class="section">
175 <h2><a name="Configuration-Method-Precedence">Configuration-Method-Precedence</a></h2>
176 <p>The configuration is gathered in a fix order:</p>
177 <ol style="list-style-type: decimal">
178 <li><tt>hibernate.properties</tt></li>
179 <li>maven-properties</li>
180 <li>plugin-configuration</li></ol>
181 <p>If you are in doubt about where a configuration-value comes from, run maven with the <a href="./debugging.html">debug-output</a> enabled: <tt>mvn -X hibernate4:export</tt> and be aware, that maven-properties can be overwitten on the command-line, in your <tt>~/.m2/settings.xml</tt> and in a profile.</p>
182 <p>The plugin-configuration comes last and overwrites everything else. That way, you can be sure, that a configuration-value, that is specified in the plugin-configuration will never be overwritten by any other configuration-method.</p>
183 <p>If you realy need to overwrite plugin-configuration-values with maven-properties, you can use maven-properties in the plugin-configuration:</p>
184 <div>
185 <pre>&lt;plugin&gt;
186   &lt;groupId&gt;de.juplo&lt;/groupId&gt;
187   &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
188   &lt;version&gt;${project.version}&lt;/version&gt;
189   &lt;executions&gt;
190     &lt;execution&gt;
191       &lt;goals&gt;
192         &lt;goal&gt;export&lt;/goal&gt;
193       &lt;/goals&gt;
194     &lt;/execution&gt;
195   &lt;/executions&gt;
196   &lt;configuration&gt;
197     &lt;password&gt;${my-password-property}&lt;/password&gt;
198   &lt;/configuration&gt;
199 &lt;/plugin&gt;</pre></div></div>
200         </section>
201         <div class="marginal">
202           <nav id="nav">
203             <hr class="n" />
204             <a class="hide" href="#top" title="Show Content">Jump back to the top of the page</a>
205             <h2 class="nav menu">Section-Menu</h2>
206             <ul id="menu">
207               <li class="m blog"><a href="/blog/" class="m">Blog</a></li>
208               <li class="m projects"><a href="/projects.html" class="m selected">Projects</a></li>
209             </ul>
210             <h2 class="nav submenu">
211               <span class="s">Submenu for section</span>
212               <a class="s selected" href="/projects.html">Projects</a>
213             </h2>
214             <ul id="submenu" class="s">
215                                                               <li class="s sub">
216                                           <a class="s selected" href="./index.html">Hibernate 4 Maven Plugin</a>
217                                         <ul class="s active">
218                                                                                                                                                                                                                                                                 <li class="s">
219               <strong class="s">Configuration Examples</strong>
220                 </li>
221                                                                                                                   <li class="s">
222                     <a href="export-mojo.html" class="s" title="Parameter Documentation">Parameter Documentation</a>
223                 </li>
224                                                                                                                   <li class="s">
225                     <a href="debugging.html" class="s" title="Enable Debug-Output">Enable Debug-Output</a>
226                 </li>
227                                                                                                                   <li class="s">
228                     <a href="force.html" class="s" title="Force Exceution">Force Exceution</a>
229                 </li>
230                                                                                                                   <li class="s">
231                     <a href="pitfalls.html" class="s" title="Known Pitfalls (FAQ)">Known Pitfalls (FAQ)</a>
232                 </li>
233                                                                                                                                                                                                                                                                                                                                         <li class="s sub">
234                     <a href="project-info.html" class="s" title="Project Information">Project Information</a>
235                 </li>
236                                                                                                                                                                                         <li class="s sub">
237                     <a href="project-reports.html" class="s" title="Project Reports">Project Reports</a>
238                 </li>
239                                                                                               </ul>
240                   </li>
241                                           </ul>
242             <hr class="n" />
243           </nav>
244           <p>
245             <a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy">
246               <img class="poweredBy" alt="Built by Maven" src="./images/logos/maven-feather.png" />
247             </a>
248           </p>
249         </div>
250       </main>
251       <footer id="footer">
252         <hr class="f" />
253         <ul id="footerlinks">
254           <li class="f" id="copyright">© <strong>mo</strong> 2013</li>
255           <li class="f"><a class="f" href="/impressum.html">Impressum</a></li>
256           <li class="f about"><a class="f" href="/about.html">About</a></li>
257         </ul>
258       </footer>
259     </div>
260         <script type="text/javascript"><!--//--><![CDATA[//><!--
261       var _gaq = _gaq || [];
262       _gaq.push(['_setAccount', 'UA-571104-3']);
263       _gaq.push(['_trackPageview']);
264       (function() {
265         var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
266         ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
267         var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
268       })();
269     //--><!]]>
270       </body>
271 </html>