Hibernate Error : JavaReflectionManager cannot be cast to MetadataProviderInjector

Problem

Using Hibernate annotation, after upgraded Hibernate version from v3.2.7 to v3.6, it hits following error message :


Caused by: java.lang.ClassCastException: 
	org.hibernate.annotations.common.reflection.java.JavaReflectionManager 
	cannot be cast to org.hibernate.annotations.common.reflection.MetadataProviderInjector

Here’s the list of the Hibernate annotation libraries :

  1. hibernate3-3.6.0.Final.jar
  2. hibernate-annotations-3.4.0.GA.jar
  3. hibernate-commons-annotations-3.0.0.GA.jar

Solution

Hibernate annotation module is merged into Hibernate core module since v3.5 (if not mistake). In this case, Hibernate is detected two annotation modules, from both “Hibernate core” and “Hibernate annotation“, causing conflict and prompt the ClassCastException.

To fix it, just delete both of the hibernate-annotations-3.4.0.GA.jar and hibernate-commons-annotations-3.0.0.GA.jar, because latest Hibernate core library is able to perform annotation task without other dependency.

15 comments on “Hibernate Error : JavaReflectionManager cannot be cast to MetadataProviderInjector

  1. Hi,
    A I have not worked my proposed solution. I get the following error:
    GRAVE: StandardWrapper.Throwable
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sessionFactory’ defined in ServletContext resource [/ WEB-INF/spring-servlet.xml]: Invocation of init method failed; nested exception is java.lang.ClassCastException: org.hibernate.annotations.common.reflection.java.JavaReflectionManager can not be cast to org.hibernate.annotations.common.reflection.MetadataProviderInjector

    I deleted the references to hibernate-annotations and hibernate-commons-annotations.
    Any other solution?
    thanks

  2. Attractive section of content. I just stumbled upon your blog and in accession capital to assert
    that I acquire actually enjoyed account your blog posts.
    Anyway I will be subscribing to your feeds and even I achievement you access
    consistently rapidly.

  3. Mkyong, your website is really very much helpful.

    I too had the same problem as mentioned above, but if I remove hibernate-annotations and commons-ann… I am not able to use AnnotationConfiguration().configure().buildSesssionFactory().

    please advise.

    Regds
    Srini

  4. Thanks a lot, i had no idea about how to solve this problem, your work in this blog is amazing, has helped me a lot for a long time with many problems.

  5. Nope,

    Not working that solution, the 3.60 hibernate distribution is not reporting annotations in my NetBeans environment so, no way to have working JPA 2 with Hibernate lastest distributions due the

    Caused by: java.lang.ClassCastException:
    org.hibernate.annotations.common.reflection.java.JavaReflectionManager
    cannot be cast to org.hibernate.annotations.common.reflection.MetadataProviderInjector

    Error…

Leave a Comment

Your email address will not be published. Required fields are marked *