X-Git-Url: https://juplo.de/gitweb/?p=website;a=blobdiff_plain;f=dist%2Fhibernate-maven-plugin-2.1.0%2Fpitfalls.html;fp=dist%2Fhibernate-maven-plugin-2.1.0%2Fpitfalls.html;h=346141946789fe379b3c44fff8bcdac26931cf2e;hp=0000000000000000000000000000000000000000;hb=a53595184bd6e57bdc45292cc92c393c4e2dfe6e;hpb=c48c9ee0e9faa89a4c0a5323b367b9f5a6abe602 diff --git a/dist/hibernate-maven-plugin-2.1.0/pitfalls.html b/dist/hibernate-maven-plugin-2.1.0/pitfalls.html new file mode 100644 index 00000000..34614194 --- /dev/null +++ b/dist/hibernate-maven-plugin-2.1.0/pitfalls.html @@ -0,0 +1,732 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Hibernate Maven Plugin — Known Pitfalls (FAQ) + + + + +

Path

+

+

    +
  1. Hibernate Maven Plugin
  2. Known Pitfalls (FAQ)
+

+
+
+ + + + +

Known Pitfalls (FAQ)

+ +
+

Annotated classes in dependencies are not found.

+ +

+ hibernate-maven-plugin by default scans dependencies in the scope + compile. You can configure it to scan dependencies in other + scopes as well. But it scans only direct dependencies. Transitive + dependencies are not scanned for annotated classes. If some of your + annotated classes are hidden in a transitive dependency, you can simply + add that dependency explicitly. +

+
+
+

hibernate-maven-plugin always needs a database-connection

+ +

+ The default-configuration executes the created SQL. + Therefore, it needs a valid database-connection and fails, if none is + available. + If you do not need the generated SQL to be executed automatically, + you can set the property hibernate.schema.execute to + false. + This can be achieved with the command-line parameter + -Dhibernate.schema.execute=false or with the following + configuration: +

+ +
+
+<configuration>
+  <execute>false</execute>
+</configuration>
+ +

+ But even when no database is to be created, hibernate always needs to know + the dialect. Hence, the plugin will still fail, if this parameter is also + 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 runtime. +

+ +

+ But this will break the execution of the hibernate-maven-plugin. + 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.H2Dialect
+[INFO]   hibernate.connection.url = jdbc:h2:file:./db
+[INFO]   hibernate.hbm2dll.create_namespaces = false
+[INFO]   hibernate.connection.driver_class = org.h2.Driver
+[INFO]   hibernate.format_sql = true
+[INFO] HHH000412: Hibernate Core {5.0.2.Final}
+[INFO] HHH000206: hibernate.properties not found
+[INFO] HHH000021: Bytecode provider name : javassist
+[INFO] Adding /home/kai/project/target/classes to the list of roots to scan...
+[INFO] Adding dependencies from scope compile to the list of roots to scan
+[INFO] Adding dependencies from scope org.hibernate:hibernate-core:jar:4.3.0.Final to the list of roots to scan
+[INFO] Adding annotated resource: de.juplo.tests.SimplestMavenHib4Test
+[INFO] ------------------------------------------------------------------------
+[INFO] BUILD FAILURE
+[INFO] ------------------------------------------------------------------------
+[INFO] Total time: 1.760s
+[INFO] Finished at: Mon Mar 07 19:06:54 CET 2016
+[INFO] Final Memory: 11M/215M
+[INFO] ------------------------------------------------------------------------
+[ERROR] Failed to execute goal de.juplo:hibernate-maven-plugin:2.1.0: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]
+[ERROR] 
+[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
+[ERROR] Re-run Maven using the -X switch to enable full debug logging.
+[ERROR] 
+[ERROR] For more information about the errors and possible solutions, please read the following articles:
+[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
+ +

+ 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: +

+ +
+
+<plugin>
+  <groupId>de.juplo</groupId>
+  <artifactId>hibernate-maven-plugin</artifactId>
+  <version>2.1.0</version>
+  <executions>
+    <execution>
+      <goals>
+        <goal>drop</goal>
+        <goal>create</goal>
+      </goals>
+    </execution>
+  </executions>
+  <dependencies>
+  <dependency>
+    <groupId>org.hsqldb</groupId>
+    <artifactId>hsqldb</artifactId>
+    <version>2.2.8</version>
+  </dependency>
+  </dependencies>
+</plugin>
+ +

+ 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 hibernate was skipped because nothing has changed

+ +

+ If hibernate-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 dbunit-plugin, + the CLEAN_INSERT-operation may fail because of foreign-key-constraints, + if the database was not recreated, because the hibernate-maven-plugin has + skipped its excecution. +

+ +

+ A quick fix to this problem is, to force + hibernate-maven-plugin to generate and execute the SQL 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, hibernate-maven-plugin signals a skipped + excecution by setting the maven property ${hibernate.schema.skipped} to + true. + You can configure other plugins to react on this signal. + For example, the dbunit-plugin can be configured to skip its excecution, if + hibernate-maven-plugin was skipped like this: +

+ +
+
+<plugin>
+  <groupId>org.codehaus.mojo</groupId>
+  <artifactId>dbunit-maven-plugin</artifactId>
+  <configuration>
+    <skip>${hibernate.schema.skipped}</skip>
+  </configuration>
+</plugin>
+
+
+

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 hibernate-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 mvn clean for cleanup, this will not happen. + Otherwise the recreation must be forced: +

+ +
+
+mvn hibernate:create -Dhibernate.schema.force=true
+
+
+

The hibernate:create goal is not executed, when tests are skipped

+ +

+ The hibernate-maven-plugin automatically skips its execution, when + maven.test.skip is set to true. If you need it to be always + executed, you can configure that explicitly like this: +

+ +
+
+<plugin>
+  <groupId>de.juplo</groupId>
+  <artifactId>hibernate-maven-plugin</artifactId>
+  ...
+  <configuration>
+    <skip>false</skip>
+  </configuration>
+</plugin>
+ +

+ Background-information for this design-decission can be found on the extra + page To skip or not to skip: that is the question... +

+
+
+

I do not want my dependencies to be scanned for hibernate annotations

+ +

+ If you do not want your dependencies to be scanned for hibernate annotations, + you can pass -Dhibernate.schema.scan.dependencies=none to maven + or set scanDependencies to none in the configuration + of the plugin like this: +

+ +
+
+<plugin>
+  <groupId>de.juplo</groupId>
+  <artifactId>hibernate-maven-plugin</artifactId>
+  ...
+  <configuration>
+    <scanDependencies>none</scanDependencies>
+  </configuration>
+</plugin>
+
+
+

No annotated classes found

+ +

+ If you are working under Windows and get the error-message + No annotated classes found in directory C:\projects\X Y Z\path-to-project\target\classes, + but you are really sure, that there are annotated classes in that + directory, you are expiriencing a bug, in the scannotation-library, that + was closed in version 1.1.0 of the hibernate-maven-plugin. +

+ +

+ + You should consider to upgrade to the latest version of the plugin. + +

+
+
+

If two goals are specified, the second one is always skipped

+ +

+ If you specify two goals, for example drop and + create, each goal has to be specified in its own + execution, so that you can specify two different + output-files for the two goals. + Otherwise, both goals will use the same output-file and the goal, that + is run second, will always skip, becaus it will find, that the output + file already exists and conclude, that its work was already done in a + prior run. +

+ +

+ Example configuration for two goals: +

+ +
+
+<executions>
+  <execution>
+    <id>Create Drop-Schema</id>
+    <phase>test-compile</phase>
+    <goals>
+      <goal>drop</goal>
+    </goals>
+    <configuration>
+      <outputFile>db-schema/drop-schema.ddl</outputFile>
+    </configuration>
+  </execution>
+  <execution>
+    <id>Create Create-Schema</id>
+    <phase>test-compile</phase>
+    <goals>
+      <goal>create</goal>
+    </goals>
+    <configuration>
+      <outputFile>db-schema/create-schema.ddl</outputFile>
+    </configuration>
+  </execution>
+</executions>
+
+ +
+
+

Pages

+

+

+

+ +