5bbbff126e548669147a8eea55ab7c874bacb57a
[hibernate4-maven-plugin] / src / site / apt / pitfalls.apt
1 Known Pitfalls
2
3 * Dependency for driver-class XYZ is missing
4
5   One regular problem is the scope of the jdbc-driver-dependency.
6   It is very unlikely, that this dependency is needed at compile-time.
7   So a tidy maven-developer would usually scope it for <<<runtime>>>.
8
9   But this will break the execution of the <<<hibernate4-maven-plugin>>>.
10   Since it will not be able to see the needed dependency, it will fail with
11   an error-message like:
12
13 ---------------
14 [INFO] Gathered hibernate-configuration (turn on debugging for details):
15 [INFO]   hibernate.connection.username = sa
16 [INFO]   hibernate.connection.password = 
17 [INFO]   hibernate.dialect = org.hibernate.dialect.HSQLDialect
18 [INFO]   hibernate.connection.url = jdbc:hsqldb:/home/kai/mmf/target/mmf;shutdown=true
19 [INFO]   hibernate.connection.driver_class = org.hsqldb.jdbcDriver
20 [ERROR] Dependency for driver-class org.hsqldb.jdbcDriver is missing!
21 [INFO] ------------------------------------------------------------------------
22 [ERROR] BUILD ERROR
23 [INFO] ------------------------------------------------------------------------
24 [INFO] org.hsqldb.jdbcDriver
25 [INFO] ------------------------------------------------------------------------
26 [INFO] For more information, run Maven with the -e switch
27 [INFO] ------------------------------------------------------------------------
28 [INFO] Total time: 2 seconds
29 [INFO] Finished at: Thu Nov 29 11:31:14 CET 2012
30 [INFO] Final Memory: 32M/342M
31 [INFO] ------------------------------------------------------------------------
32 ---------------
33
34   A quick workaround for this error would be, to delete the runtime-constraint
35   for the jdbc-driver-dependency.
36
37   A much cleaner way is, to (additionally) ad the dependency, to the
38   plugin-definition:
39
40 ---------------
41 <plugin>
42   <groupId>de.juplo</groupId>
43   <artifactId>hibernate4-maven-plugin</artifactId>
44   <version>${project.version}</version>
45   <executions>
46     <execution>
47       <goals>
48         <goal>export</goal>
49       </goals>
50     </execution>
51   </executions>
52   <dependencies>
53   <dependency>
54     <groupId>org.hsqldb</groupId>
55     <artifactId>hsqldb</artifactId>
56     <version>2.2.8</version>
57   </dependency>
58   </dependencies>
59 </plugin>
60 ---------------
61
62   This is also the best way, if you use a different jdbc-driver for
63   testing, than in production.
64   Because otherwise, this dependency will unnecessarily bloat the
65   runtime-dependencies of your project.
66
67 * DBUnit {fails} after execution of hibernate4 was skipped because nothing has changed
68
69   If hibernate4-maven-plugin skips its excecution, this may lead to errors in
70   other plugins.
71   For example, when importing sample-data in the automatically created database
72   with the help of the {{{http://mojo.codehaus.org/dbunit-maven-plugin/}dbunit-plugin}},
73   the <<<CLEAN_INSERT>>>-operation may fail because of foreign-key-constraints,
74   if the database was not recreated, because the hibernate4-maven-plugin has
75   skipped its excecution.
76
77   A quick fix to this problem is, to {{{./force.html}force}}
78   hibernate4-maven-plugin to export the schema every time it is running.
79   But to recreate the database on every testrun may noticeable slow down your
80   development cycle, if you have to wait for slow IO.
81
82   To circumvent this problem, hibernate4-maven-plugin signals a skipped
83   excecution by setting the  maven property <<<${hibernate.export.skipped}>>> to
84   <<<true>>>.
85   You can configure other plugins to react on this signal.
86   For example, the dbunit-plugin can be configured to skip its excecution, if
87   hibernate4-maven-plugin was skipped like this:
88
89 ------------
90 <plugin>
91   <groupId>org.codehaus.mojo</groupId>
92   <artifactId>dbunit-maven-plugin</artifactId>
93   <configuration>
94     <skip>${hibernate.export.skipped}</skip>
95   </configuration>
96 </plugin>
97 ------------