Main Tutorials

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.

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
15 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
sfbayman
10 years ago

It worked. thank you.

xerx593
5 years ago

the thank i s to you, mykong! 🙂 https://stackoverflow.com/q/54401402/592355

Neelesh
7 years ago

Your solutions always hit the bullseye!! Thanks a lot!

Danilo Cardoso
8 years ago

You’re the guy. Thanks a lot!

aleixen
9 years ago

Thanks!!! it works now!

Ankit Katiyar
9 years ago

Thanks a lot.

chandrashekhargoka
10 years ago

Its working thank you

Maria
10 years ago

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

Hugh
10 years ago

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.

Manuela
10 years ago

Thank you soo much!

Srini
10 years ago

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

Hasan
11 years ago

Thank You MK,

From three days I’have been searching for the problem and you made it a
sweet 😉

Marvin Campos
11 years ago

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.

mperk
11 years ago

Thanks..
This good solution. Thanks again.

Israel
13 years ago

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…