Projekt-Dokumentation (Aktueller Stand von juplo.de) hinzugefĆ¼gt
[website] / dist / hibernate4-maven-plugin-1.0.4 / pitfalls.html
1 <!DOCTYPE html>
2 <!-- Generated by Apache Maven Doxia Site Renderer 1.4 at 2014-06-02 -->
3                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               <!-- Current: pitfalls.html -->
4 <!-- Active: index.html -->
5 <!-- Path: [index.html, pitfalls.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 - Known Pitfalls (FAQ)</title>
10     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
11     <link rel="canonical" href="http://juplo.de/hibernate4-maven-plugin/pitfalls.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">Known Pitfalls (FAQ)</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>Known Pitfalls (FAQ)</h1></header>
51           
52  
53  
54   
55 <div class="section">
56 <h2>Annotated classes in dependencies are not found.<a name="Annotated_classes_in_dependencies_are_not_found."></a></h2>
57   
58 <p>
59   hibernate4-maven-plugin by default scans dependencies in the scope
60   <tt>compile</tt>. You can configure it to scan dependencies in other
61   scopes as well. But it scans only direct dependencies. Transitive
62   dependencies are not scanned for annotated classes. If some of your
63   annotated classes are hidden in a transitive dependency, you can simply
64   add that dependency explicitly.
65   </p>
66   </div>
67 <div class="section">
68 <h2>hibernate4-maven-plugin always needs a database-connection<a name="hibernate4-maven-plugin_always_needs_a_database-connection"></a></h2>
69   
70 <p>
71   The default-configuration uses the EXPORT-target of the SchemaExport-Tool.
72   If you do not need to create a database with the evaluated schema, you can
73   use the NONE- or the SCRIPT-target.
74   This can be achieved with the command-line parameter
75   <tt>-Dhibernate.export.target=SCRIPT</tt> or with the following configuration:
76   </p>
77   
78 <div>
79 <pre class="prettyprint linenums lang-html">
80 &lt;configuration&gt;
81   &lt;target&gt;SCRIPT&lt;/target&gt;
82 &lt;/configuration&gt;</pre></div>
83   
84 <p>
85   But even when no database is to be created, hibernate always needs to know
86   the dialect. Hence, the plugin will fail if this parameter is missing!
87   </p>
88   </div>
89 <div class="section">
90 <h2>Dependency for driver-class XYZ is missing<a name="Dependency_for_driver-class_XYZ_is_missing"></a></h2>
91   
92 <p>
93   One regular problem is the scope of the jdbc-driver-dependency.
94   It is very unlikely, that this dependency is needed at compile-time.
95   So a tidy maven-developer would usually scope it for <tt>runtime</tt>.
96   </p>
97   
98 <p>
99   But this will break the execution of the <tt>hibernate4-maven-plugin</tt>.
100   Since it will not be able to see the needed dependency, it will fail with
101   an error-message like:
102   </p>
103   
104 <div>
105 <pre class="prettyprint">
106 [INFO] Gathered hibernate-configuration (turn on debugging for details):
107 [INFO]   hibernate.connection.username = sa
108 [INFO]   hibernate.connection.password = 
109 [INFO]   hibernate.dialect = org.hibernate.dialect.HSQLDialect
110 [INFO]   hibernate.connection.url = jdbc:hsqldb:/home/kai/mmf/target/mmf;shutdown=true
111 [INFO]   hibernate.connection.driver_class = org.hsqldb.jdbcDriver
112 [ERROR] Dependency for driver-class org.hsqldb.jdbcDriver is missing!
113 [INFO] ------------------------------------------------------------------------
114 [ERROR] BUILD ERROR
115 [INFO] ------------------------------------------------------------------------
116 [INFO] org.hsqldb.jdbcDriver
117 [INFO] ------------------------------------------------------------------------
118 [INFO] For more information, run Maven with the -e switch
119 [INFO] ------------------------------------------------------------------------
120 [INFO] Total time: 2 seconds
121 [INFO] Finished at: Thu Nov 29 11:31:14 CET 2012
122 [INFO] Final Memory: 32M/342M
123 [INFO] ------------------------------------------------------------------------</pre></div>
124   
125 <p>
126   A quick workaround for this error would be, to delete the runtime-constraint
127   for the jdbc-driver-dependency.
128   </p>
129   
130 <p>
131   A much cleaner way is, to (additionally) ad the dependency, to the
132   plugin-definition:
133   </p>
134   
135 <div>
136 <pre class="prettyprint linenums lang-html">
137 &lt;plugin&gt;
138   &lt;groupId&gt;de.juplo&lt;/groupId&gt;
139   &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
140   &lt;version&gt;1.0.4&lt;/version&gt;
141   &lt;executions&gt;
142     &lt;execution&gt;
143       &lt;goals&gt;
144         &lt;goal&gt;export&lt;/goal&gt;
145       &lt;/goals&gt;
146     &lt;/execution&gt;
147   &lt;/executions&gt;
148   &lt;dependencies&gt;
149   &lt;dependency&gt;
150     &lt;groupId&gt;org.hsqldb&lt;/groupId&gt;
151     &lt;artifactId&gt;hsqldb&lt;/artifactId&gt;
152     &lt;version&gt;2.2.8&lt;/version&gt;
153   &lt;/dependency&gt;
154   &lt;/dependencies&gt;
155 &lt;/plugin&gt;</pre></div>
156   
157 <p>
158   This is also the best way, if you use a different jdbc-driver for
159   testing, than in production.
160   Because otherwise, this dependency will unnecessarily bloat the
161   runtime-dependencies of your project.
162   </p>
163   </div>
164 <div class="section" id="fails">
165 <h2 id="fails">DBUnit fails after execution of hibernate4 was skipped because nothing has changed</h2>
166   
167 <p>
168   If hibernate4-maven-plugin skips its excecution, this may lead to errors in
169   other plugins.
170   For example, when importing sample-data in the automatically created database
171   with the help of the <a class="externalLink" href="http://mojo.codehaus.org/dbunit-maven-plugin/">dbunit-plugin</a>,
172   the <tt>CLEAN_INSERT</tt>-operation may fail because of foreign-key-constraints,
173   if the database was not recreated, because the hibernate4-maven-plugin has
174   skipped its excecution.
175   </p>
176   
177 <p>
178   A quick fix to this problem is, to <a href="./force.html">force</a>
179   hibernate4-maven-plugin to export the schema every time it is running.
180   But to recreate the database on every testrun may noticeable slow down your
181   development cycle, if you have to wait for slow IO.
182   </p>
183   
184 <p>
185   To circumvent this problem, hibernate4-maven-plugin signals a skipped
186   excecution by setting the  maven property <tt>$\{hibernate.export.skipped\}</tt> to
187   <tt>true</tt>.
188   You can configure other plugins to react on this signal.
189   For example, the dbunit-plugin can be configured to skip its excecution, if
190   hibernate4-maven-plugin was skipped like this:
191   </p>
192   
193 <div>
194 <pre class="prettyprint linenums lang-html">
195 &lt;plugin&gt;
196   &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
197   &lt;artifactId&gt;dbunit-maven-plugin&lt;/artifactId&gt;
198   &lt;configuration&gt;
199     &lt;skip&gt;${hibernate.export.skipped}&lt;/skip&gt;
200   &lt;/configuration&gt;
201 &lt;/plugin&gt;</pre></div>
202   </div>
203 <div class="section">
204 <h2>The database will not be recreated after a manual drop/clean<a name="The_database_will_not_be_recreated_after_a_manual_dropclean"></a></h2>
205   
206 <p>
207   If one manually drops the database or removes the hsqldb-files, it will not
208   be recreated by the hibernate4-maven-plugin, because it cannot detect, that
209   the database needs to be recreated.
210   This happens, because the plugin will not recreate the database if neither
211   the configuration nor the annotated classes have changed, because an
212   unnecessary drop-create-cycle might take a long time. The plugin will
213   report that like this:
214   </p>
215   
216 <div>
217 <pre class="prettyprint">
218 [INFO] No modified annotated classes found and dialect unchanged.
219 [INFO] Skipping schema generation!</pre></div>
220   
221 <p>
222   If one always uses <tt>mvn clean</tt> for cleanup, this will not happen.
223   Otherwise the recreation must be <a href="./force.html">forced</a>:
224   </p>
225   
226 <div>
227 <pre class="prettyprint">
228 mvn hibernate4:export -Dhibernate.export.force=true</pre></div>
229   </div>
230 <div class="section">
231 <h2>The hibernate4:export goal is not executed, when tests are skipped<a name="The_hibernate4:export_goal_is_not_executed_when_tests_are_skipped"></a></h2>
232   
233 <p>
234   The hibernate4-maven-plugin automatically skips its execution, when
235   <tt>maven.test.skip</tt> is set to <tt>true</tt>. If you need it to be always
236   executed, you can configure that explicitly like this:
237   </p>
238   
239 <div>
240 <pre class="prettyprint linenums lang-html">
241 &gt;plugin&lt;
242   &lt;groupId&gt;de.juplo&lt;/groupId&gt;
243   &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
244   ...
245   &lt;configuration&gt;
246     &lt;skip&gt;false&lt;/skip&gt;
247   &lt;/configuration&gt;
248 &lt;/plugin&gt;</pre></div>
249   
250 <p>
251   Background-information for this design-decission can be found on the extra
252   page <a href="./skip.html">To skip or not to skip: that is the question</a>...
253   </p>
254  </div>
255
256         </article>
257         <div class="marginal">
258           <nav id="nav">
259             <hr class="n" />
260             <a id="navigation"></a>
261             <a class="hide" href="#top" title="Show Content">Jump back to the top of the page</a>
262             <h2 class="nav menu">Section-Menu</h2>
263             <ul id="menu">
264               <li class="m blog"><a href="/blog/" class="m">Blog</a></li>
265               <li class="m projects"><a href="/projects.html" class="m selected">Projects</a></li>
266               <li class="m about"><a href="/about.html" class="m">About</a></li>
267             </ul>
268             <h2 class="nav submenu">
269               <span class="s">Submenu for section</span>
270               <a class="s selected" href="/projects.html">Projects</a>
271             </h2>
272             <ul id="submenu" class="s">
273                                                               <li class="s sub">
274                                           <a class="s selected" href="./index.html">Hibernate 4 Maven Plugin</a>
275                                         <ul class="s active">
276                                                                                                                                                                                                                                                           <li class="s">
277                     <a href="configuration.html" class="s" title="Configuration Examples">Configuration Examples</a>
278                 </li>
279                                                                                                                   <li class="s">
280                     <a href="export-mojo.html" class="s" title="Parameter Documentation">Parameter Documentation</a>
281                 </li>
282                                                                                                                   <li class="s">
283                     <a href="debugging.html" class="s" title="Enable Debug-Output">Enable Debug-Output</a>
284                 </li>
285                                                                                                                   <li class="s">
286                     <a href="skip.html" class="s" title="Skipping Execution">Skipping Execution</a>
287                 </li>
288                                                                                                                   <li class="s">
289                     <a href="force.html" class="s" title="Force Exceution">Force Exceution</a>
290                 </li>
291                                                                                                                         <li class="s">
292               <strong class="s">Known Pitfalls (FAQ)</strong>
293                 </li>
294                                                                                                                                                                                                                                                                                                                                                   <li class="s sub">
295                     <a href="project-info.html" class="s" title="Project Information">Project Information</a>
296                 </li>
297                                                                                                                                                                                                   <li class="s sub">
298                     <a href="project-reports.html" class="s" title="Project Reports">Project Reports</a>
299                 </li>
300                                                                                               </ul>
301                   </li>
302                                           </ul>
303             <hr class="n" />
304           </nav>
305           <aside class="m">
306             <a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy">
307               <img class="poweredBy" alt="Built by Maven" src="./images/logos/maven-feather.png" />
308             </a>
309           </aside>
310         </div>
311       </main>
312       <footer id="footer">
313         <hr class="f" />
314         <ul id="footerlinks">
315           <li class="f" id="copyright">&#xa9; <strong>mo</strong>             2014
316       </li>
317           <li class="f"><a class="f" href="/impressum.html">Impressum</a></li>
318           <li class="f about"><a class="f" href="/about.html">About</a></li>
319         </ul>
320       </footer>
321     </div>
322         <script type="text/javascript"><!--//--><![CDATA[//><!--
323       var _gaq = _gaq || [];
324       _gaq.push(['_setAccount', 'UA-571104-3']);
325       _gaq.push(['_trackPageview']);
326       (function() {
327         var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
328         ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
329         var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
330       })();
331     //--><!]]>
332     </script>
333       </body>
334 </html>