Fixed bug in site-configuration
[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 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
16 hibernate4-maven-plugin always needs a database-connection
17
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   <<<-Dhibernate.export.target=SCRIPT>>> or with the following configuration:
23
24 ------------
25 <configuration>
26   <target>SCRIPT</target>
27 </configuration>
28 ------------
29
30   But even when no database is to be created, hibernate always needs to know
31   the dialect. Hence, the plugin will fail if this parameter is missing!
32
33 Dependency for driver-class XYZ is missing
34
35   One regular problem is the scope of the jdbc-driver-dependency.
36   It is very unlikely, that this dependency is needed at compile-time.
37   So a tidy maven-developer would usually scope it for <<<runtime>>>.
38
39   But this will break the execution of the <<<hibernate4-maven-plugin>>>.
40   Since it will not be able to see the needed dependency, it will fail with
41   an error-message like:
42
43 ---------------
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] ------------------------------------------------------------------------
62 ---------------
63
64   A quick workaround for this error would be, to delete the runtime-constraint
65   for the jdbc-driver-dependency.
66
67   A much cleaner way is, to (additionally) ad the dependency, to the
68   plugin-definition:
69
70 ---------------
71 <plugin>
72   <groupId>de.juplo</groupId>
73   <artifactId>hibernate4-maven-plugin</artifactId>
74   <version>${project.version}</version>
75   <executions>
76     <execution>
77       <goals>
78         <goal>export</goal>
79       </goals>
80     </execution>
81   </executions>
82   <dependencies>
83   <dependency>
84     <groupId>org.hsqldb</groupId>
85     <artifactId>hsqldb</artifactId>
86     <version>2.2.8</version>
87   </dependency>
88   </dependencies>
89 </plugin>
90 ---------------
91
92   This is also the best way, if you use a different jdbc-driver for
93   testing, than in production.
94   Because otherwise, this dependency will unnecessarily bloat the
95   runtime-dependencies of your project.
96
97 DBUnit {fails} after execution of hibernate4 was skipped because nothing has changed
98
99   If hibernate4-maven-plugin skips its excecution, this may lead to errors in
100   other plugins.
101   For example, when importing sample-data in the automatically created database
102   with the help of the {{{http://mojo.codehaus.org/dbunit-maven-plugin/}dbunit-plugin}},
103   the <<<CLEAN_INSERT>>>-operation may fail because of foreign-key-constraints,
104   if the database was not recreated, because the hibernate4-maven-plugin has
105   skipped its excecution.
106
107   A quick fix to this problem is, to {{{./force.html}force}}
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
112   To circumvent this problem, hibernate4-maven-plugin signals a skipped
113   excecution by setting the  maven property <<<${hibernate.export.skipped}>>> to
114   <<<true>>>.
115   You can configure other plugins to react on this signal.
116   For example, the dbunit-plugin can be configured to skip its excecution, if
117   hibernate4-maven-plugin was skipped like this:
118
119 ------------
120 <plugin>
121   <groupId>org.codehaus.mojo</groupId>
122   <artifactId>dbunit-maven-plugin</artifactId>
123   <configuration>
124     <skip>${hibernate.export.skipped}</skip>
125   </configuration>
126 </plugin>
127 ------------
128
129 The database will not be recreated after a manual drop/clean
130
131   If one manually drops the database or removes the hsqldb-files, it will not
132   be recreated by the hibernate4-maven-plugin, because it cannot detect, that
133   the database needs to be recreated.
134   This happens, because the plugin will not recreate the database if neither
135   the configuration nor the annotated classes have changed, because an
136   unnecessary drop-create-cycle might take a long time. The plugin will
137   report that like this:
138
139 -------------
140 [INFO] No modified annotated classes found and dialect unchanged.
141 [INFO] Skipping schema generation!
142 -------------
143
144   If one always uses <<<mvn clean>>> for cleanup, this will not happen.
145   Otherwise the recreation must be {{{./force.html}forced}}:
146
147 -------------
148 mvn hibernate4:export -Dhibernate.export.force=true
149 -------------
150
151 The hibernate4:export goal is not executed, when tests are skipped
152
153   The hibernate4-maven-plugin automatically skips its execution, when
154   <<<maven.test.skip>>> is set to <<<true>>>. If you need it to be always
155   executed, you can configure that explicitly like this:
156
157 ------------
158 <plugin>
159   <groupId>de.juplo</groupId>
160   <artifactId>hibernate4-maven-plugin</artifactId>
161   ...
162   <configuration>
163     <skip>false</skip>
164   </configuration>
165 </plugin>
166 ------------
167
168   Background-information for this design-decission can be found on the extra
169   page {{{./skip.html}To skip or not to skip: that is the question}}...