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 the Author

author image
mkyong
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

avatar
15 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
15 Comment authors
xerx593NeeleshDanilo CardosoaleixenAnkit Katiyar Recent comment authors
newest oldest most voted
xerx593
Guest
xerx593

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

Neelesh
Guest
Neelesh

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

Danilo Cardoso
Guest
Danilo Cardoso

You’re the guy. Thanks a lot!

aleixen
Guest
aleixen

Thanks!!! it works now!

Ankit Katiyar
Guest
Ankit Katiyar

Thanks a lot.

chandrashekhargoka
Guest
chandrashekhargoka

Its working thank you

sfbayman
Guest
sfbayman

It worked. thank you.

Maria
Guest
Maria

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
Guest
Hugh

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
Guest
Manuela

Thank you soo much!

Srini
Guest
Srini

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
Guest
Hasan

Thank You MK,

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

Marvin Campos
Guest
Marvin Campos

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
Guest
mperk

Thanks..
This good solution. Thanks again.

Israel
Guest
Israel

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…