Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hibernate-core & hibernate-annotation - conflicting

I am getting the error:

java.lang.VerifyError: (class: org/hibernate/type/BasicTypeRegistry, method:  signature: ()V) Incompatible argument to function     
at org.hibernate.type.TypeResolver.(TypeResolver.java:59)   
at com.gs.ctt.cb.types.usertypes.GenericEnumUserType.setParameterValues(GenericEnumUserType.java:46) 
at org.hibernate.type.TypeFactory.injectParameters(TypeFactory.java:339)



As the possible cause is conflicting libraries, I figured out that that class: org.hibernate.cfg.AnnotationConfiguration is available in both:

  • hibernate-annotations-3.3.0
  • hibernate-core-3.6.4

Do I need to get rid of hibernate-annotations at all? Why?

like image 412
Sandeep Jindal Avatar asked Dec 15 '25 07:12

Sandeep Jindal


1 Answers

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>

And the 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>
like image 56
ug_ Avatar answered Dec 16 '25 22:12

ug_



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!