Added FAQ-entry for problem with whitespaces in the path under Windows
[hibernate4-maven-plugin] / src / site / xhtml / pitfalls.xhtml
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3  <head>
4  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5  </head>
6  <body>
7   <h2>Annotated classes in dependencies are not found.</h2>
8   <p>
9   hibernate4-maven-plugin by default scans dependencies in the scope
10   <code>compile</code>. You can configure it to scan dependencies in other
11   scopes as well. But it scans only direct dependencies. Transitive
12   dependencies are not scanned for annotated classes. If some of your
13   annotated classes are hidden in a transitive dependency, you can simply
14   add that dependency explicitly.
15   </p>
16   <h2>hibernate4-maven-plugin always needs a database-connection</h2>
17   <p>
18   The default-configuration uses the EXPORT-target of the SchemaExport-Tool.
19   If you do not need to create a database with the evaluated schema, you can
20   use the NONE- or the SCRIPT-target.
21   This can be achieved with the command-line parameter
22   <code>-Dhibernate.export.target=SCRIPT</code> or with the following configuration:
23   </p>
24   <pre class="prettyprint linenums lang-html">
25 &lt;configuration&gt;
26   &lt;target&gt;SCRIPT&lt;/target&gt;
27 &lt;/configuration&gt;</pre>
28   <p>
29   But even when no database is to be created, hibernate always needs to know
30   the dialect. Hence, the plugin will fail if this parameter is missing!
31   </p>
32   <h2>Dependency for driver-class XYZ is missing</h2>
33   <p>
34   One regular problem is the scope of the jdbc-driver-dependency.
35   It is very unlikely, that this dependency is needed at compile-time.
36   So a tidy maven-developer would usually scope it for <code>runtime</code>.
37   </p>
38   <p>
39   But this will break the execution of the <code>hibernate4-maven-plugin</code>.
40   Since it will not be able to see the needed dependency, it will fail with
41   an error-message like:
42   </p>
43   <pre class="prettyprint">
44 [INFO] Gathered hibernate-configuration (turn on debugging for details):
45 [INFO]   hibernate.connection.username = sa
46 [INFO]   hibernate.connection.password = 
47 [INFO]   hibernate.dialect = org.hibernate.dialect.HSQLDialect
48 [INFO]   hibernate.connection.url = jdbc:hsqldb:/home/kai/mmf/target/mmf;shutdown=true
49 [INFO]   hibernate.connection.driver_class = org.hsqldb.jdbcDriver
50 [ERROR] Dependency for driver-class org.hsqldb.jdbcDriver is missing!
51 [INFO] ------------------------------------------------------------------------
52 [ERROR] BUILD ERROR
53 [INFO] ------------------------------------------------------------------------
54 [INFO] org.hsqldb.jdbcDriver
55 [INFO] ------------------------------------------------------------------------
56 [INFO] For more information, run Maven with the -e switch
57 [INFO] ------------------------------------------------------------------------
58 [INFO] Total time: 2 seconds
59 [INFO] Finished at: Thu Nov 29 11:31:14 CET 2012
60 [INFO] Final Memory: 32M/342M
61 [INFO] ------------------------------------------------------------------------</pre>
62   <p>
63   A quick workaround for this error would be, to delete the runtime-constraint
64   for the jdbc-driver-dependency.
65   </p>
66   <p>
67   A much cleaner way is, to (additionally) ad the dependency, to the
68   plugin-definition:
69   </p>
70   <pre class="prettyprint linenums lang-html">
71 &lt;plugin&gt;
72   &lt;groupId&gt;de.juplo&lt;/groupId&gt;
73   &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
74   &lt;version&gt;${project.version}&lt;/version&gt;
75   &lt;executions&gt;
76     &lt;execution&gt;
77       &lt;goals&gt;
78         &lt;goal&gt;export&lt;/goal&gt;
79       &lt;/goals&gt;
80     &lt;/execution&gt;
81   &lt;/executions&gt;
82   &lt;dependencies&gt;
83   &lt;dependency&gt;
84     &lt;groupId&gt;org.hsqldb&lt;/groupId&gt;
85     &lt;artifactId&gt;hsqldb&lt;/artifactId&gt;
86     &lt;version&gt;2.2.8&lt;/version&gt;
87   &lt;/dependency&gt;
88   &lt;/dependencies&gt;
89 &lt;/plugin&gt;</pre>
90   <p>
91   This is also the best way, if you use a different jdbc-driver for
92   testing, than in production.
93   Because otherwise, this dependency will unnecessarily bloat the
94   runtime-dependencies of your project.
95   </p>
96   <h2 id="fails">DBUnit fails after execution of hibernate4 was skipped because nothing has changed</h2>
97   <p>
98   If hibernate4-maven-plugin skips its excecution, this may lead to errors in
99   other plugins.
100   For example, when importing sample-data in the automatically created database
101   with the help of the <a href="http://mojo.codehaus.org/dbunit-maven-plugin/">dbunit-plugin</a>,
102   the <code>CLEAN_INSERT</code>-operation may fail because of foreign-key-constraints,
103   if the database was not recreated, because the hibernate4-maven-plugin has
104   skipped its excecution.
105   </p>
106   <p>
107   A quick fix to this problem is, to <a href="./force.html">force</a>
108   hibernate4-maven-plugin to export the schema every time it is running.
109   But to recreate the database on every testrun may noticeable slow down your
110   development cycle, if you have to wait for slow IO.
111   </p>
112   <p>
113   To circumvent this problem, hibernate4-maven-plugin signals a skipped
114   excecution by setting the  maven property <code>$\{hibernate.export.skipped\}</code> to
115   <code>true</code>.
116   You can configure other plugins to react on this signal.
117   For example, the dbunit-plugin can be configured to skip its excecution, if
118   hibernate4-maven-plugin was skipped like this:
119   </p>
120   <pre class="prettyprint linenums lang-html">
121 &lt;plugin&gt;
122   &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
123   &lt;artifactId&gt;dbunit-maven-plugin&lt;/artifactId&gt;
124   &lt;configuration&gt;
125     &lt;skip&gt;${hibernate.export.skipped}&lt;/skip&gt;
126   &lt;/configuration&gt;
127 &lt;/plugin&gt;</pre>
128   <h2>The database will not be recreated after a manual drop/clean</h2>
129   <p>
130   If one manually drops the database or removes the hsqldb-files, it will not
131   be recreated by the hibernate4-maven-plugin, because it cannot detect, that
132   the database needs to be recreated.
133   This happens, because the plugin will not recreate the database if neither
134   the configuration nor the annotated classes have changed, because an
135   unnecessary drop-create-cycle might take a long time. The plugin will
136   report that like this:
137   </p>
138   <pre class="prettyprint">
139 [INFO] No modified annotated classes found and dialect unchanged.
140 [INFO] Skipping schema generation!</pre>
141   <p>
142   If one always uses <code>mvn clean</code> for cleanup, this will not happen.
143   Otherwise the recreation must be <a href="./force.html">forced</a>:
144   </p>
145   <pre class="prettyprint">
146 mvn hibernate4:export -Dhibernate.export.force=true</pre>
147   <h2>The hibernate4:export goal is not executed, when tests are skipped</h2>
148   <p>
149   The hibernate4-maven-plugin automatically skips its execution, when
150   <code>maven.test.skip</code> is set to <code>true</code>. If you need it to be always
151   executed, you can configure that explicitly like this:
152   </p>
153   <pre class="prettyprint linenums lang-html">
154 &lt;plugin&gt;
155   &lt;groupId&gt;de.juplo&lt;/groupId&gt;
156   &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
157   ...
158   &lt;configuration&gt;
159     &lt;skip&gt;false&lt;/skip&gt;
160   &lt;/configuration&gt;
161 &lt;/plugin&gt;</pre>
162   <p>
163   Background-information for this design-decission can be found on the extra
164   page <a href="./skip.html">To skip or not to skip: that is the question</a>...
165   </p>
166   <h2>I do not want my dependencies to be scanned for hibernate annotations</h2>
167   <p>
168     If you do not want your dependencies to be scanned for hibernate annotations,
169     you can pass <code>-Dhibernate.export.scan_dependencies=none</code> to maven
170     or set <code>scanDependencies</code> to <code>none</code> in the configuration
171     of the plugin like this:
172   </p>
173   <pre class="prettyprint linenums lang-html">
174 &lt;plugin&gt;
175   &lt;groupId&gt;de.juplo&lt;/groupId&gt;
176   &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
177   ...
178   &lt;configuration&gt;
179     &lt;scanDependencies&gt;none&lt;/scanDependencies&gt;
180   &lt;/configuration&gt;
181 &lt;/plugin&gt;</pre>
182   <h2>No annotated classes found</h2>
183   <p>
184     If you are working under Windows and get the error-message
185     <code>No annotated classes found in directory C:\projects\X Y Z\path-to-project\target\classes</code>,
186     but you are really sure, that there are annotated classes in that
187     directory, you should try to rename your folders, so that their names
188     do not contain any whitespaces.
189   </p>
190   <p>
191     So fare, I got to bug-reports considering this.
192     In both cases, removing all whitespaces from the path solved the error.
193     In both cases, I was not able to reproduce the bug on my development
194     system, which is running under linux.
195   </p>
196   <p>
197     <strong>
198       Hence, I assume, this is a sublte bug in the way, the java-version for
199       Windows is handling paths, that contain whitespaces.
200     </strong>
201   </p>
202  </body>
203 </html>