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 exports the created schema to the configured
21 Therefore, it needs a valid database-connection and fails, if none is
23 If you do not need to export the created schema to a database,
24 you can set the property <code>hibernate.schema.export</code> to
26 This can be achieved with the command-line parameter
27 <code>-Dhibernate.schema.export=false</code> or with the following
30 <pre class="prettyprint linenums lang-html">
32 <export>false</export>
33 </configuration></pre>
35 But even when no database is to be created, hibernate always needs to know
36 the dialect. Hence, the plugin will still fail, if this parameter is also
39 <h2>Dependency for driver-class XYZ is missing</h2>
41 One regular problem is the scope of the jdbc-driver-dependency.
42 It is very unlikely, that this dependency is needed at compile-time.
43 So a tidy maven-developer would usually scope it for <code>runtime</code>.
46 But this will break the execution of the <code>hibernate-maven-plugin</code>.
47 Since it will not be able to see the needed dependency, it will fail with
48 an error-message like:
50 <pre class="prettyprint">
51 [INFO] Gathered hibernate-configuration (turn on debugging for details):
52 [INFO] hibernate.connection.username = sa
53 [INFO] hibernate.connection.password =
54 [INFO] hibernate.dialect = org.hibernate.dialect.H2Dialect
55 [INFO] hibernate.connection.url = jdbc:h2:file:./db
56 [INFO] hibernate.hbm2dll.create_namespaces = false
57 [INFO] hibernate.connection.driver_class = org.h2.Driver
58 [INFO] hibernate.format_sql = true
59 [INFO] HHH000412: Hibernate Core {5.0.2.Final}
60 [INFO] HHH000206: hibernate.properties not found
61 [INFO] HHH000021: Bytecode provider name : javassist
62 [INFO] Adding /home/kai/project/target/classes to the list of roots to scan...
63 [INFO] Adding dependencies from scope compile to the list of roots to scan
64 [INFO] Adding dependencies from scope org.hibernate:hibernate-core:jar:4.3.0.Final to the list of roots to scan
65 [INFO] Adding annotated resource: de.juplo.tests.SimplestMavenHib4Test
66 [INFO] ------------------------------------------------------------------------
68 [INFO] ------------------------------------------------------------------------
69 [INFO] Total time: 1.760s
70 [INFO] Finished at: Mon Mar 07 19:06:54 CET 2016
71 [INFO] Final Memory: 11M/215M
72 [INFO] ------------------------------------------------------------------------
73 [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]
75 [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
76 [ERROR] Re-run Maven using the -X switch to enable full debug logging.
78 [ERROR] For more information about the errors and possible solutions, please read the following articles:
79 [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException</pre>
81 A quick workaround for this error would be, to delete the runtime-constraint
82 for the jdbc-driver-dependency.
85 A much cleaner way is, to (additionally) ad the dependency, to the
88 <pre class="prettyprint linenums lang-html">
90 <groupId>de.juplo</groupId>
91 <artifactId>hibernate-maven-plugin</artifactId>
92 <version>${project.version}</version>
96 <goal>drop</goal>
97 <goal>create</goal>
103 <groupId>org.hsqldb</groupId>
104 <artifactId>hsqldb</artifactId>
105 <version>2.2.8</version>
107 </dependencies>
108 </plugin></pre>
110 This is also the best way, if you use a different jdbc-driver for
111 testing, than in production.
112 Because otherwise, this dependency will unnecessarily bloat the
113 runtime-dependencies of your project.
115 <h2 id="fails">DBUnit fails after execution of hibernate was skipped because nothing has changed</h2>
117 If hibernate-maven-plugin skips its excecution, this may lead to errors in
119 For example, when importing sample-data in the automatically created database
120 with the help of the <a href="http://mojo.codehaus.org/dbunit-maven-plugin/">dbunit-plugin</a>,
121 the <code>CLEAN_INSERT</code>-operation may fail because of foreign-key-constraints,
122 if the database was not recreated, because the hibernate-maven-plugin has
123 skipped its excecution.
126 A quick fix to this problem is, to <a href="./force.html">force</a>
127 hibernate-maven-plugin to export the schema every time it is running.
128 But to recreate the database on every testrun may noticeable slow down your
129 development cycle, if you have to wait for slow IO.
132 To circumvent this problem, hibernate-maven-plugin signals a skipped
133 excecution by setting the maven property <code>${hibernate.schema.skipped}</code> to
135 You can configure other plugins to react on this signal.
136 For example, the dbunit-plugin can be configured to skip its excecution, if
137 hibernate-maven-plugin was skipped like this:
139 <pre class="prettyprint linenums lang-html">
141 <groupId>org.codehaus.mojo</groupId>
142 <artifactId>dbunit-maven-plugin</artifactId>
143 <configuration>
144 <skip>${hibernate.schema.skipped}</skip>
145 </configuration>
146 </plugin></pre>
147 <h2>The database will not be recreated after a manual drop/clean</h2>
149 If one manually drops the database or removes the hsqldb-files, it will not
150 be recreated by the hibernate-maven-plugin, because it cannot detect, that
151 the database needs to be recreated.
152 This happens, because the plugin will not recreate the database if neither
153 the configuration nor the annotated classes have changed, because an
154 unnecessary drop-create-cycle might take a long time. The plugin will
155 report that like this:
157 <pre class="prettyprint">
158 [INFO] No modified annotated classes found and dialect unchanged.
159 [INFO] Skipping schema generation!</pre>
161 If one always uses <code>mvn clean</code> for cleanup, this will not happen.
162 Otherwise the recreation must be <a href="./force.html">forced</a>:
164 <pre class="prettyprint">
165 mvn hibernate:create -Dhibernate.schema.force=true</pre>
166 <h2>The hibernate:create goal is not executed, when tests are skipped</h2>
168 The hibernate-maven-plugin automatically skips its execution, when
169 <code>maven.test.skip</code> is set to <code>true</code>. If you need it to be always
170 executed, you can configure that explicitly like this:
172 <pre class="prettyprint linenums lang-html">
174 <groupId>de.juplo</groupId>
175 <artifactId>hibernate-maven-plugin</artifactId>
177 <configuration>
178 <skip>false</skip>
179 </configuration>
180 </plugin></pre>
182 Background-information for this design-decission can be found on the extra
183 page <a href="./skip.html">To skip or not to skip: that is the question</a>...
185 <h2>I do not want my dependencies to be scanned for hibernate annotations</h2>
187 If you do not want your dependencies to be scanned for hibernate annotations,
188 you can pass <code>-Dhibernate.schema.scan.dependencies=none</code> to maven
189 or set <code>scanDependencies</code> to <code>none</code> in the configuration
190 of the plugin like this:
192 <pre class="prettyprint linenums lang-html">
194 <groupId>de.juplo</groupId>
195 <artifactId>hibernate-maven-plugin</artifactId>
197 <configuration>
198 <scanDependencies>none</scanDependencies>
199 </configuration>
200 </plugin></pre>
201 <h2>No annotated classes found</h2>
203 If you are working under Windows and get the error-message
204 <code>No annotated classes found in directory C:\projects\X Y Z\path-to-project\target\classes</code>,
205 but you are really sure, that there are annotated classes in that
206 directory, you are expiriencing a bug, in the scannotation-library, that
207 was closed in version 1.1.0 of the hibernate-maven-plugin.
211 You should consider to upgrade to the latest version of the plugin.