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">
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
7 <header><h1>Known Pitfalls (FAQ)</h1></header>
8 <h2>Annotated classes in dependencies are not found.</h2>
10 hibernate-maven-plugin by default scans dependencies in the scope
11 <code>compile</code>. You can configure it to scan dependencies in other
12 scopes as well. But it scans only direct dependencies. Transitive
13 dependencies are not scanned for annotated classes. If some of your
14 annotated classes are hidden in a transitive dependency, you can simply
15 add that dependency explicitly.
17 <h2>hibernate-maven-plugin always needs a database-connection</h2>
19 The default-configuration executes the created SQL.
20 Therefore, it needs a valid database-connection and fails, if none is
22 If you do not need the generated SQL to be executed automatically,
23 you can set the property <code>hibernate.schema.execute</code> to
25 This can be achieved with the command-line parameter
26 <code>-Dhibernate.schema.execute=false</code> or with the following
29 <pre class="prettyprint linenums lang-html">
31 <execute>false</execute>
32 </configuration></pre>
34 But even when no database is to be created, hibernate always needs to know
35 the dialect. Hence, the plugin will still fail, if this parameter is also
38 <h2>Dependency for driver-class XYZ is missing</h2>
40 One regular problem is the scope of the jdbc-driver-dependency.
41 It is very unlikely, that this dependency is needed at compile-time.
42 So a tidy maven-developer would usually scope it for <code>runtime</code>.
45 But this will break the execution of the <code>hibernate-maven-plugin</code>.
46 Since it will not be able to see the needed dependency, it will fail with
47 an error-message like:
49 <pre class="prettyprint">
50 [INFO] Gathered hibernate-configuration (turn on debugging for details):
51 [INFO] hibernate.connection.username = sa
52 [INFO] hibernate.connection.password =
53 [INFO] hibernate.dialect = org.hibernate.dialect.H2Dialect
54 [INFO] hibernate.connection.url = jdbc:h2:file:./db
55 [INFO] hibernate.hbm2dll.create_namespaces = false
56 [INFO] hibernate.connection.driver_class = org.h2.Driver
57 [INFO] hibernate.format_sql = true
58 [INFO] HHH000412: Hibernate Core {5.0.2.Final}
59 [INFO] HHH000206: hibernate.properties not found
60 [INFO] HHH000021: Bytecode provider name : javassist
61 [INFO] Adding /home/kai/project/target/classes to the list of roots to scan...
62 [INFO] Adding dependencies from scope compile to the list of roots to scan
63 [INFO] Adding dependencies from scope org.hibernate:hibernate-core:jar:4.3.0.Final to the list of roots to scan
64 [INFO] Adding annotated resource: de.juplo.tests.SimplestMavenHib4Test
65 [INFO] ------------------------------------------------------------------------
67 [INFO] ------------------------------------------------------------------------
68 [INFO] Total time: 1.760s
69 [INFO] Finished at: Mon Mar 07 19:06:54 CET 2016
70 [INFO] Final Memory: 11M/215M
71 [INFO] ------------------------------------------------------------------------
72 [ERROR] Failed to execute goal de.juplo:hibernate-maven-plugin:${project.version}: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 -> [Help 1]
74 [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
75 [ERROR] Re-run Maven using the -X switch to enable full debug logging.
77 [ERROR] For more information about the errors and possible solutions, please read the following articles:
78 [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException</pre>
80 A quick workaround for this error would be, to delete the runtime-constraint
81 for the jdbc-driver-dependency.
84 A much cleaner way is, to (additionally) ad the dependency, to the
87 <pre class="prettyprint linenums lang-html">
89 <groupId>de.juplo</groupId>
90 <artifactId>hibernate-maven-plugin</artifactId>
91 <version>${project.version}</version>
95 <goal>drop</goal>
96 <goal>create</goal>
102 <groupId>org.hsqldb</groupId>
103 <artifactId>hsqldb</artifactId>
104 <version>2.2.8</version>
106 </dependencies>
107 </plugin></pre>
109 This is also the best way, if you use a different jdbc-driver for
110 testing, than in production.
111 Because otherwise, this dependency will unnecessarily bloat the
112 runtime-dependencies of your project.
114 <h2 id="fails">DBUnit fails after execution of hibernate was skipped because nothing has changed</h2>
116 If hibernate-maven-plugin skips its excecution, this may lead to errors in
118 For example, when importing sample-data in the automatically created database
119 with the help of the <a href="http://mojo.codehaus.org/dbunit-maven-plugin/">dbunit-plugin</a>,
120 the <code>CLEAN_INSERT</code>-operation may fail because of foreign-key-constraints,
121 if the database was not recreated, because the hibernate-maven-plugin has
122 skipped its excecution.
125 A quick fix to this problem is, to <a href="./force.html">force</a>
126 hibernate-maven-plugin to generate and execute the SQL every time it is running.
127 But to recreate the database on every testrun may noticeable slow down your
128 development cycle, if you have to wait for slow IO.
131 To circumvent this problem, hibernate-maven-plugin signals a skipped
132 excecution by setting the maven property <code>${hibernate.schema.skipped}</code> to
134 You can configure other plugins to react on this signal.
135 For example, the dbunit-plugin can be configured to skip its excecution, if
136 hibernate-maven-plugin was skipped like this:
138 <pre class="prettyprint linenums lang-html">
140 <groupId>org.codehaus.mojo</groupId>
141 <artifactId>dbunit-maven-plugin</artifactId>
142 <configuration>
143 <skip>${hibernate.schema.skipped}</skip>
144 </configuration>
145 </plugin></pre>
146 <h2>The database will not be recreated after a manual drop/clean</h2>
148 If one manually drops the database or removes the hsqldb-files, it will not
149 be recreated by the hibernate-maven-plugin, because it cannot detect, that
150 the database needs to be recreated.
151 This happens, because the plugin will not recreate the database if neither
152 the configuration nor the annotated classes have changed, because an
153 unnecessary drop-create-cycle might take a long time. The plugin will
154 report that like this:
156 <pre class="prettyprint">
157 [INFO] No modified annotated classes found and dialect unchanged.
158 [INFO] Skipping schema generation!</pre>
160 If one always uses <code>mvn clean</code> for cleanup, this will not happen.
161 Otherwise the recreation must be <a href="./force.html">forced</a>:
163 <pre class="prettyprint">
164 mvn hibernate:create -Dhibernate.schema.force=true</pre>
165 <h2>The hibernate:create goal is not executed, when tests are skipped</h2>
167 The hibernate-maven-plugin automatically skips its execution, when
168 <code>maven.test.skip</code> is set to <code>true</code>. If you need it to be always
169 executed, you can configure that explicitly like this:
171 <pre class="prettyprint linenums lang-html">
173 <groupId>de.juplo</groupId>
174 <artifactId>hibernate-maven-plugin</artifactId>
176 <configuration>
177 <skip>false</skip>
178 </configuration>
179 </plugin></pre>
181 Background-information for this design-decission can be found on the extra
182 page <a href="./skip.html">To skip or not to skip: that is the question</a>...
184 <h2>I do not want my dependencies to be scanned for hibernate annotations</h2>
186 If you do not want your dependencies to be scanned for hibernate annotations,
187 you can pass <code>-Dhibernate.schema.scan.dependencies=none</code> to maven
188 or set <code>scanDependencies</code> to <code>none</code> in the configuration
189 of the plugin like this:
191 <pre class="prettyprint linenums lang-html">
193 <groupId>de.juplo</groupId>
194 <artifactId>hibernate-maven-plugin</artifactId>
196 <configuration>
197 <scanDependencies>none</scanDependencies>
198 </configuration>
199 </plugin></pre>
200 <h2>No annotated classes found</h2>
202 If you are working under Windows and get the error-message
203 <code>No annotated classes found in directory C:\projects\X Y Z\path-to-project\target\classes</code>,
204 but you are really sure, that there are annotated classes in that
205 directory, you are expiriencing a bug, in the scannotation-library, that
206 was closed in version 1.1.0 of the hibernate-maven-plugin.
210 You should consider to upgrade to the latest version of the plugin.