Known Pitfalls * hibernate4-maven-plugin always needs a database-connection The default-configuration uses the EXPORT-target of the SchemaExport-Tool. If you do not need to create a database with the evaluated schema, you can use the NONE- or the SCRIPT-target. This can be achieved with the commandline-parameter <<<-Dhibernate.export.target=SCRIPT>>> or with the following configuration: ------------ SCRIPT ------------ But even when no database is to be created, hibernate always needs to know the dialect. Hence, the plugin will fail if this parameter is missing! * Dependency for driver-class XYZ is missing One regular problem is the scope of the jdbc-driver-dependency. It is very unlikely, that this dependency is needed at compile-time. So a tidy maven-developer would usually scope it for <<>>. But this will break the execution of the <<>>. Since it will not be able to see the needed dependency, it will fail with an error-message like: --------------- [INFO] Gathered hibernate-configuration (turn on debugging for details): [INFO] hibernate.connection.username = sa [INFO] hibernate.connection.password = [INFO] hibernate.dialect = org.hibernate.dialect.HSQLDialect [INFO] hibernate.connection.url = jdbc:hsqldb:/home/kai/mmf/target/mmf;shutdown=true [INFO] hibernate.connection.driver_class = org.hsqldb.jdbcDriver [ERROR] Dependency for driver-class org.hsqldb.jdbcDriver is missing! [INFO] ------------------------------------------------------------------------ [ERROR] BUILD ERROR [INFO] ------------------------------------------------------------------------ [INFO] org.hsqldb.jdbcDriver [INFO] ------------------------------------------------------------------------ [INFO] For more information, run Maven with the -e switch [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2 seconds [INFO] Finished at: Thu Nov 29 11:31:14 CET 2012 [INFO] Final Memory: 32M/342M [INFO] ------------------------------------------------------------------------ --------------- A quick workaround for this error would be, to delete the runtime-constraint for the jdbc-driver-dependency. A much cleaner way is, to (additionally) ad the dependency, to the plugin-definition: --------------- de.juplo hibernate4-maven-plugin ${project.version} export org.hsqldb hsqldb 2.2.8 --------------- This is also the best way, if you use a different jdbc-driver for testing, than in production. Because otherwise, this dependency will unnecessarily bloat the runtime-dependencies of your project. * DBUnit {fails} after execution of hibernate4 was skipped because nothing has changed If hibernate4-maven-plugin skips its excecution, this may lead to errors in other plugins. For example, when importing sample-data in the automatically created database with the help of the {{{http://mojo.codehaus.org/dbunit-maven-plugin/}dbunit-plugin}}, the <<>>-operation may fail because of foreign-key-constraints, if the database was not recreated, because the hibernate4-maven-plugin has skipped its excecution. A quick fix to this problem is, to {{{./force.html}force}} hibernate4-maven-plugin to export the schema every time it is running. But to recreate the database on every testrun may noticeable slow down your development cycle, if you have to wait for slow IO. To circumvent this problem, hibernate4-maven-plugin signals a skipped excecution by setting the maven property <<<${hibernate.export.skipped}>>> to <<>>. You can configure other plugins to react on this signal. For example, the dbunit-plugin can be configured to skip its excecution, if hibernate4-maven-plugin was skipped like this: ------------ org.codehaus.mojo dbunit-maven-plugin ${hibernate.export.skipped} ------------ * The database will not be recreated after a manual drop/clean If one manually drops the database or removes the hsqldb-files, it will not be recreated by the hibernate4-maven-plugin, because it cannot detect, that the database needs to be recreated. This happens, because the plugin will not recreate the database if neither the configuration nor the annotated classes have changed, because an unnecessary drop-create-cycle might take a long time. The plugin will report that like this: ------------- [INFO] No modified annotated classes found and dialect unchanged. [INFO] Skipping schema generation! ------------- If one always uses <<>> for cleanup, this will not happen. Otherwise the recreation must be {{{./force.html}forced}}: ------------- mvn hibernate4:export -Dhibernate.export.force=true ------------- * The hibernate4:export goal is executed, even if <<>> is <<>> Up to version 1.0.2 the hibernate4-maven-plugin automatically skipped its execution, when <<>> was set to <<>>. Starting with version 1.0.3 this behaviour was changed. The plugin now only skips its execution, when explicitliy told so via the configuration-parameter <<>> or via the property <<>>. This change was made, because in some use-cases it is necessary, that the database-schema is always build and/or exported, even if the tests are skipped, which was not possible with the old behaviour. If you need/like the old behaviour, you can turn it on in your configuration: ------------ de.juplo hibernate4-maven-plugin ... ${maven.test.skip} ------------