WIP-thymeleaf-skin: layout-dialect ausgebaut -- Anpassung an thymeroot-skin
[website] / dist / hibernate-maven-plugin-2.0.0 / pitfalls.html
1 <!DOCTYPE html>
2 <!-- Generated by Apache Maven Doxia Site Renderer 1.6 at 2016-03-09 -->
3                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       <!-- Current: pitfalls.html -->
4 <!-- Active: index.html -->
5 <!-- Path: [index.html, pitfalls.html] -->
6 <!-- Skiplist: [index.html, configuration.html, create-mojo.html, drop-mojo.html, debugging.html, skip.html, force.html, pitfalls.html] -->
7 <html>
8   <head>
9     <title>juplo - Hibernate 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/hibernate-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 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   hibernate-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="hibernate-maven-plugin_always_needs_a_database-connection"></a>hibernate-maven-plugin always needs a database-connection</h2>
65   
66 <p>
67   The default-configuration exports the created schema to the configured
68   database.
69   Therefore, it needs a valid database-connection and fails, if none is
70   available.
71   If you do not need to export the created schema to a database,
72   you can set the property <tt>hibernate.schema.export</tt> to
73   <tt>false</tt>.
74   This can be achieved with the command-line parameter
75   <tt>-Dhibernate.schema.export=false</tt> or with the following
76   configuration:
77   </p>
78   
79 <div>
80 <pre class="prettyprint linenums lang-html">
81 &lt;configuration&gt;
82   &lt;export&gt;false&lt;/export&gt;
83 &lt;/configuration&gt;</pre></div>
84   
85 <p>
86   But even when no database is to be created, hibernate always needs to know
87   the dialect. Hence, the plugin will still fail, if this parameter is also
88   missing!
89   </p>
90   </div>
91 <div class="section">
92 <h2><a name="Dependency_for_driver-class_XYZ_is_missing"></a>Dependency for driver-class XYZ is missing</h2>
93   
94 <p>
95   One regular problem is the scope of the jdbc-driver-dependency.
96   It is very unlikely, that this dependency is needed at compile-time.
97   So a tidy maven-developer would usually scope it for <tt>runtime</tt>.
98   </p>
99   
100 <p>
101   But this will break the execution of the <tt>hibernate-maven-plugin</tt>.
102   Since it will not be able to see the needed dependency, it will fail with
103   an error-message like:
104   </p>
105   
106 <div>
107 <pre class="prettyprint">
108 [INFO] Gathered hibernate-configuration (turn on debugging for details):
109 [INFO]   hibernate.connection.username = sa
110 [INFO]   hibernate.connection.password = 
111 [INFO]   hibernate.dialect = org.hibernate.dialect.H2Dialect
112 [INFO]   hibernate.connection.url = jdbc:h2:file:./db
113 [INFO]   hibernate.hbm2dll.create_namespaces = false
114 [INFO]   hibernate.connection.driver_class = org.h2.Driver
115 [INFO]   hibernate.format_sql = true
116 [INFO] HHH000412: Hibernate Core {5.0.2.Final}
117 [INFO] HHH000206: hibernate.properties not found
118 [INFO] HHH000021: Bytecode provider name : javassist
119 [INFO] Adding /home/kai/project/target/classes to the list of roots to scan...
120 [INFO] Adding dependencies from scope compile to the list of roots to scan
121 [INFO] Adding dependencies from scope org.hibernate:hibernate-core:jar:4.3.0.Final to the list of roots to scan
122 [INFO] Adding annotated resource: de.juplo.tests.SimplestMavenHib4Test
123 [INFO] ------------------------------------------------------------------------
124 [INFO] BUILD FAILURE
125 [INFO] ------------------------------------------------------------------------
126 [INFO] Total time: 1.760s
127 [INFO] Finished at: Mon Mar 07 19:06:54 CET 2016
128 [INFO] Final Memory: 11M/215M
129 [INFO] ------------------------------------------------------------------------
130 [ERROR] Failed to execute goal de.juplo:hibernate-maven-plugin:2.0.0:drop (default) on project hibernate4-properties-test: Could not open the JDBC-connection: Unable to load class [org.h2.Driver]: Could not load requested class : org.h2.Driver -&gt; [Help 1]
131 [ERROR] 
132 [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
133 [ERROR] Re-run Maven using the -X switch to enable full debug logging.
134 [ERROR] 
135 [ERROR] For more information about the errors and possible solutions, please read the following articles:
136 [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException</pre></div>
137   
138 <p>
139   A quick workaround for this error would be, to delete the runtime-constraint
140   for the jdbc-driver-dependency.
141   </p>
142   
143 <p>
144   A much cleaner way is, to (additionally) ad the dependency, to the
145   plugin-definition:
146   </p>
147   
148 <div>
149 <pre class="prettyprint linenums lang-html">
150 &lt;plugin&gt;
151   &lt;groupId&gt;de.juplo&lt;/groupId&gt;
152   &lt;artifactId&gt;hibernate-maven-plugin&lt;/artifactId&gt;
153   &lt;version&gt;2.0.0&lt;/version&gt;
154   &lt;executions&gt;
155     &lt;execution&gt;
156       &lt;goals&gt;
157         &lt;goal&gt;drop&lt;/goal&gt;
158         &lt;goal&gt;create&lt;/goal&gt;
159       &lt;/goals&gt;
160     &lt;/execution&gt;
161   &lt;/executions&gt;
162   &lt;dependencies&gt;
163   &lt;dependency&gt;
164     &lt;groupId&gt;org.hsqldb&lt;/groupId&gt;
165     &lt;artifactId&gt;hsqldb&lt;/artifactId&gt;
166     &lt;version&gt;2.2.8&lt;/version&gt;
167   &lt;/dependency&gt;
168   &lt;/dependencies&gt;
169 &lt;/plugin&gt;</pre></div>
170   
171 <p>
172   This is also the best way, if you use a different jdbc-driver for
173   testing, than in production.
174   Because otherwise, this dependency will unnecessarily bloat the
175   runtime-dependencies of your project.
176   </p>
177   </div>
178 <div class="section" id="fails">
179 <h2 id="fails">DBUnit fails after execution of hibernate was skipped because nothing has changed</h2>
180   
181 <p>
182   If hibernate-maven-plugin skips its excecution, this may lead to errors in
183   other plugins.
184   For example, when importing sample-data in the automatically created database
185   with the help of the <a class="externalLink" href="http://mojo.codehaus.org/dbunit-maven-plugin/">dbunit-plugin</a>,
186   the <tt>CLEAN_INSERT</tt>-operation may fail because of foreign-key-constraints,
187   if the database was not recreated, because the hibernate-maven-plugin has
188   skipped its excecution.
189   </p>
190   
191 <p>
192   A quick fix to this problem is, to <a href="./force.html">force</a>
193   hibernate-maven-plugin to export the schema every time it is running.
194   But to recreate the database on every testrun may noticeable slow down your
195   development cycle, if you have to wait for slow IO.
196   </p>
197   
198 <p>
199   To circumvent this problem, hibernate-maven-plugin signals a skipped
200   excecution by setting the  maven property <tt>${hibernate.schema.skipped}</tt> to
201   <tt>true</tt>.
202   You can configure other plugins to react on this signal.
203   For example, the dbunit-plugin can be configured to skip its excecution, if
204   hibernate-maven-plugin was skipped like this:
205   </p>
206   
207 <div>
208 <pre class="prettyprint linenums lang-html">
209 &lt;plugin&gt;
210   &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
211   &lt;artifactId&gt;dbunit-maven-plugin&lt;/artifactId&gt;
212   &lt;configuration&gt;
213     &lt;skip&gt;${hibernate.schema.skipped}&lt;/skip&gt;
214   &lt;/configuration&gt;
215 &lt;/plugin&gt;</pre></div>
216   </div>
217 <div class="section">
218 <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>
219   
220 <p>
221   If one manually drops the database or removes the hsqldb-files, it will not
222   be recreated by the hibernate-maven-plugin, because it cannot detect, that
223   the database needs to be recreated.
224   This happens, because the plugin will not recreate the database if neither
225   the configuration nor the annotated classes have changed, because an
226   unnecessary drop-create-cycle might take a long time. The plugin will
227   report that like this:
228   </p>
229   
230 <div>
231 <pre class="prettyprint">
232 [INFO] No modified annotated classes found and dialect unchanged.
233 [INFO] Skipping schema generation!</pre></div>
234   
235 <p>
236   If one always uses <tt>mvn clean</tt> for cleanup, this will not happen.
237   Otherwise the recreation must be <a href="./force.html">forced</a>:
238   </p>
239   
240 <div>
241 <pre class="prettyprint">
242 mvn hibernate:create -Dhibernate.schema.force=true</pre></div>
243   </div>
244 <div class="section">
245 <h2><a name="The_hibernate:create_goal_is_not_executed_when_tests_are_skipped"></a>The hibernate:create goal is not executed, when tests are skipped</h2>
246   
247 <p>
248   The hibernate-maven-plugin automatically skips its execution, when
249   <tt>maven.test.skip</tt> is set to <tt>true</tt>. If you need it to be always
250   executed, you can configure that explicitly like this:
251   </p>
252   
253 <div>
254 <pre class="prettyprint linenums lang-html">
255 &lt;plugin&gt;
256   &lt;groupId&gt;de.juplo&lt;/groupId&gt;
257   &lt;artifactId&gt;hibernate-maven-plugin&lt;/artifactId&gt;
258   ...
259   &lt;configuration&gt;
260     &lt;skip&gt;false&lt;/skip&gt;
261   &lt;/configuration&gt;
262 &lt;/plugin&gt;</pre></div>
263   
264 <p>
265   Background-information for this design-decission can be found on the extra
266   page <a href="./skip.html">To skip or not to skip: that is the question</a>...
267   </p>
268   </div>
269 <div class="section">
270 <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>
271   
272 <p>
273     If you do not want your dependencies to be scanned for hibernate annotations,
274     you can pass <tt>-Dhibernate.schema.scan.dependencies=none</tt> to maven
275     or set <tt>scanDependencies</tt> to <tt>none</tt> in the configuration
276     of the plugin like this:
277   </p>
278   
279 <div>
280 <pre class="prettyprint linenums lang-html">
281 &lt;plugin&gt;
282   &lt;groupId&gt;de.juplo&lt;/groupId&gt;
283   &lt;artifactId&gt;hibernate-maven-plugin&lt;/artifactId&gt;
284   ...
285   &lt;configuration&gt;
286     &lt;scanDependencies&gt;none&lt;/scanDependencies&gt;
287   &lt;/configuration&gt;
288 &lt;/plugin&gt;</pre></div>
289   </div>
290 <div class="section">
291 <h2><a name="No_annotated_classes_found"></a>No annotated classes found</h2>
292   
293 <p>
294     If you are working under Windows and get the error-message
295     <tt>No annotated classes found in directory C:\projects\X Y Z\path-to-project\target\classes</tt>,
296     but you are really sure, that there are annotated classes in that
297     directory, you are expiriencing a bug, in the scannotation-library, that
298     was closed in version 1.1.0 of the hibernate-maven-plugin.
299   </p>
300   
301 <p>
302     <b>
303       You should consider to upgrade to the latest version of the plugin.
304     </b>
305   </p>
306  </div>
307
308         </article>
309         <div class="marginal">
310           <nav id="nav">
311             <hr class="n" />
312             <a id="navigation"></a>
313             <a class="hide" href="#top" title="Show Content">Jump back to the top of the page</a>
314             <h2 class="nav menu">Section-Menu</h2>
315             <ul id="menu">
316               <li class="m blog"><a href="/blog/" class="m">Blog</a></li>
317               <li class="m projects"><a href="/projects.html" class="m selected">Projects</a></li>
318               <li class="m about"><a href="/about.html" class="m">About</a></li>
319             </ul>
320             <h2 class="nav submenu">
321               <span class="s">Submenu for section</span>
322               <a class="s selected" href="/projects.html">Projects</a>
323             </h2>
324             <ul id="submenu" class="s">
325                                                               <li class="s sub">
326                                           <a class="s selected" href="./index.html">Hibernate Maven Plugin</a>
327                                         <ul class="s active">
328                                                                                                                                                                                                                                                           <li class="s">
329                     <a href="configuration.html" class="s" title="Configuration Examples">Configuration Examples</a>
330                 </li>
331                                                                                                                   <li class="s">
332                     <a href="create-mojo.html" class="s" title="Goal: CREATE">Goal: CREATE</a>
333                 </li>
334                                                                                                                   <li class="s">
335                     <a href="drop-mojo.html" class="s" title="Goal: DROP">Goal: DROP</a>
336                 </li>
337                                                                                                                   <li class="s">
338                     <a href="debugging.html" class="s" title="Enable Debug-Output">Enable Debug-Output</a>
339                 </li>
340                                                                                                                   <li class="s">
341                     <a href="skip.html" class="s" title="Skipping Execution">Skipping Execution</a>
342                 </li>
343                                                                                                                   <li class="s">
344                     <a href="force.html" class="s" title="Force Exceution">Force Exceution</a>
345                 </li>
346                                                                                                                         <li class="s">
347               <strong class="s">Known Pitfalls (FAQ)</strong>
348                 </li>
349                                                                                                                                                                                                                                                                                                                                                             <li class="s sub">
350                     <a href="project-info.html" class="s" title="Project Information">Project Information</a>
351                 </li>
352                                                                                                                                                                                                             <li class="s sub">
353                     <a href="project-reports.html" class="s" title="Project Reports">Project Reports</a>
354                 </li>
355                                                                                               </ul>
356                   </li>
357                                           </ul>
358             <hr class="n" />
359           </nav>
360           <aside class="m">
361             <a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy">
362               <img class="poweredBy" alt="Built by Maven" src="./images/logos/maven-feather.png" />
363             </a>
364           </aside>
365         </div>
366       </main>
367       <footer id="footer">
368         <hr class="f" />
369         <ul id="footerlinks">
370           <li class="f" id="copyright">&#xa9; <strong>mo</strong>             2016
371       </li>
372           <li class="f"><a class="f" href="/impressum.html">Impressum</a></li>
373           <li class="f about"><a class="f" href="/about.html">About</a></li>
374         </ul>
375       </footer>
376     </div>
377         <script type="text/javascript"><!--//--><![CDATA[//><!--
378       var _gaq = _gaq || [];
379       _gaq.push(['_setAccount', 'UA-571104-3']);
380       _gaq.push(['_trackPageview']);
381       (function() {
382         var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
383         ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
384         var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
385       })();
386     //--><!]]>
387     </script>
388       </body>
389 </html>