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 :
- hibernate3-3.6.0.Final.jar
- hibernate-annotations-3.4.0.GA.jar
- 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.
It worked. thank you.
the thank i s to you, mykong! 🙂 https://stackoverflow.com/q/54401402/592355
Your solutions always hit the bullseye!! Thanks a lot!
You’re the guy. Thanks a lot!
Thanks!!! it works now!
Thanks a lot.
Its working thank you
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
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.
Thank you soo much!
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
Thank You MK,
From three days I’have been searching for the problem and you made it a
sweet 😉
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.
Thanks..
This good solution. Thanks again.
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…