I am getting the error:
java.lang.VerifyError: (class: org/hibernate/type/BasicTypeRegistry, method: signature: ()V) Incompatible argument to function
Many dependencies in Maven also rely on other libraries to function. When including a dependency like
hibernate-core it will also automatically import its dependencies into your project, one of which is the
hibernate-annotations library. The result is 2 libraries with different versions, this is a common problem in Maven and they have provided a good way of finding where these dependencies are being imported from.
In this case just remove the
hibernate-annotations dependency from your project and let the
hibernate-core import it for you.
How would find this duplicate library conflict for yourself? One great way is to use the dependency tree plugin Maven has provided to us:
mvn dependency:tree -Dverbose -Dincludes=org.hibernate.*. This will show all library dependencies in your project that are in the group or subgroup of org.hibernate. Also consider outputting to file by appending
> fileOutputName.txt to the call so its easier to view, especially if your using the Windows command line.
Here's a sample output from a project I have that has hibernate:
<dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>4.0.1.Final</version> </dependency>
mvn dependency:tree call:
[INFO] +- org.hibernate:hibernate-core:jar:4.0.1.Final:compile [INFO] | +- (org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile - omitted for duplicate) [INFO] | \- org.hibernate.common:hibernate-commons-annotations:jar:4.0.1.Final:compile [INFO] +- org.hibernate.common:hibernate-commons-annotations:jar:tests:4.0.1.Final:compile [INFO] +- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile [INFO] \- org.hibernate:hibernate-entitymanager:jar:4.0.1.Final:compile [INFO] +- (org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile - omitted for duplicate) [INFO] \- (org.hibernate.common:hibernate-commons-annotations:jar:4.0.1.Final:compile - omitted for duplicate)
As you can see the
hibernate-core automatically imports
hibernate-commons-annotations. If that version differed from the version you include in your pom Maven will include both of them causing problems. Its best if you leave the core import to do its thing unless you have a good reason to change annotation versions.
If you really want to remove the dependency from the core library you can do so by adding the
<exclusions> tag. But watch out because there are other pieces of the hibernate suite that will try to import the annotations package, you may end up excluding the annotations from alot of dependencies.
<dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>4.0.1.Final</version> <exclusions> <exclusion> <!-- remove annotations inclusion --> <groupId>org.hibernate.common</groupId> <artifactId>hibernate-commons-annotations</artifactId> </exclusion> </exclusions> </dependency>