The plugin now scans for annotated classes in dependencies too
[hibernate4-maven-plugin] / src / site / apt / pitfalls.apt
1   ---
2   Known Pitfalls
3   ---
4   Kai Moritz
5   ---
6
7 Annotated classes in dependencies are not found.
8
9   hibernate4-maven-plugin does not scan transitive dependencies for
10   annotated classes. If some of your annotated classes are hidden in a
11   transitive dependency, you can simply add that dependency explicitly.
12
13 hibernate4-maven-plugin always needs a database-connection
14
15   The default-configuration uses the EXPORT-target of the SchemaExport-Tool.
16   If you do not need to create a database with the evaluated schema, you can
17   use the NONE- or the SCRIPT-target.
18   This can be achieved with the command-line parameter
19   <<<-Dhibernate.export.target=SCRIPT>>> or with the following configuration:
20
21 ------------
22 <configuration>
23   <target>SCRIPT</target>
24 </configuration>
25 ------------
26
27   But even when no database is to be created, hibernate always needs to know
28   the dialect. Hence, the plugin will fail if this parameter is missing!
29
30 Dependency for driver-class XYZ is missing
31
32   One regular problem is the scope of the jdbc-driver-dependency.
33   It is very unlikely, that this dependency is needed at compile-time.
34   So a tidy maven-developer would usually scope it for <<<runtime>>>.
35
36   But this will break the execution of the <<<hibernate4-maven-plugin>>>.
37   Since it will not be able to see the needed dependency, it will fail with
38   an error-message like:
39
40 ---------------
41 [INFO] Gathered hibernate-configuration (turn on debugging for details):
42 [INFO]   hibernate.connection.username = sa
43 [INFO]   hibernate.connection.password = 
44 [INFO]   hibernate.dialect = org.hibernate.dialect.HSQLDialect
45 [INFO]   hibernate.connection.url = jdbc:hsqldb:/home/kai/mmf/target/mmf;shutdown=true
46 [INFO]   hibernate.connection.driver_class = org.hsqldb.jdbcDriver
47 [ERROR] Dependency for driver-class org.hsqldb.jdbcDriver is missing!
48 [INFO] ------------------------------------------------------------------------
49 [ERROR] BUILD ERROR
50 [INFO] ------------------------------------------------------------------------
51 [INFO] org.hsqldb.jdbcDriver
52 [INFO] ------------------------------------------------------------------------
53 [INFO] For more information, run Maven with the -e switch
54 [INFO] ------------------------------------------------------------------------
55 [INFO] Total time: 2 seconds
56 [INFO] Finished at: Thu Nov 29 11:31:14 CET 2012
57 [INFO] Final Memory: 32M/342M
58 [INFO] ------------------------------------------------------------------------
59 ---------------
60
61   A quick workaround for this error would be, to delete the runtime-constraint
62   for the jdbc-driver-dependency.
63
64   A much cleaner way is, to (additionally) ad the dependency, to the
65   plugin-definition:
66
67 ---------------
68 <plugin>
69   <groupId>de.juplo</groupId>
70   <artifactId>hibernate4-maven-plugin</artifactId>
71   <version>${project.version}</version>
72   <executions>
73     <execution>
74       <goals>
75         <goal>export</goal>
76       </goals>
77     </execution>
78   </executions>
79   <dependencies>
80   <dependency>
81     <groupId>org.hsqldb</groupId>
82     <artifactId>hsqldb</artifactId>
83     <version>2.2.8</version>
84   </dependency>
85   </dependencies>
86 </plugin>
87 ---------------
88
89   This is also the best way, if you use a different jdbc-driver for
90   testing, than in production.
91   Because otherwise, this dependency will unnecessarily bloat the
92   runtime-dependencies of your project.
93
94 DBUnit {fails} after execution of hibernate4 was skipped because nothing has changed
95
96   If hibernate4-maven-plugin skips its excecution, this may lead to errors in
97   other plugins.
98   For example, when importing sample-data in the automatically created database
99   with the help of the {{{http://mojo.codehaus.org/dbunit-maven-plugin/}dbunit-plugin}},
100   the <<<CLEAN_INSERT>>>-operation may fail because of foreign-key-constraints,
101   if the database was not recreated, because the hibernate4-maven-plugin has
102   skipped its excecution.
103
104   A quick fix to this problem is, to {{{./force.html}force}}
105   hibernate4-maven-plugin to export the schema every time it is running.
106   But to recreate the database on every testrun may noticeable slow down your
107   development cycle, if you have to wait for slow IO.
108
109   To circumvent this problem, hibernate4-maven-plugin signals a skipped
110   excecution by setting the  maven property <<<${hibernate.export.skipped}>>> to
111   <<<true>>>.
112   You can configure other plugins to react on this signal.
113   For example, the dbunit-plugin can be configured to skip its excecution, if
114   hibernate4-maven-plugin was skipped like this:
115
116 ------------
117 <plugin>
118   <groupId>org.codehaus.mojo</groupId>
119   <artifactId>dbunit-maven-plugin</artifactId>
120   <configuration>
121     <skip>${hibernate.export.skipped}</skip>
122   </configuration>
123 </plugin>
124 ------------
125
126 The database will not be recreated after a manual drop/clean
127
128   If one manually drops the database or removes the hsqldb-files, it will not
129   be recreated by the hibernate4-maven-plugin, because it cannot detect, that
130   the database needs to be recreated.
131   This happens, because the plugin will not recreate the database if neither
132   the configuration nor the annotated classes have changed, because an
133   unnecessary drop-create-cycle might take a long time. The plugin will
134   report that like this:
135
136 -------------
137 [INFO] No modified annotated classes found and dialect unchanged.
138 [INFO] Skipping schema generation!
139 -------------
140
141   If one always uses <<<mvn clean>>> for cleanup, this will not happen.
142   Otherwise the recreation must be {{{./force.html}forced}}:
143
144 -------------
145 mvn hibernate4:export -Dhibernate.export.force=true
146 -------------
147
148 The hibernate4:export goal is not executed, when tests are skipped
149
150   The hibernate4-maven-plugin automatically skips its execution, when
151   <<<maven.test.skip>>> is set to <<<true>>>. If you need it to be always
152   executed, you can configure that explicitly like this:
153
154 ------------
155 <plugin>
156   <groupId>de.juplo</groupId>
157   <artifactId>hibernate4-maven-plugin</artifactId>
158   ...
159   <configuration>
160     <skip>false</skip>
161   </configuration>
162 </plugin>
163 ------------
164
165   Background-information for this design-decission can be found on the extra
166   page {{{./skip.html}To skip or not to skip: that is the question}}...