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