Main Tutorials

Hibernate Error – Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: org/hibernate/annotations/common/reflection/ReflectionManager

This is caused by missing of the Hibernate commons annotations library.


Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: 
org/hibernate/annotations/common/reflection/ReflectionManager
Exception in thread "main" java.lang.ExceptionInInitializerError
	at com.mkyong.persistence.HibernateUtil.buildSessionFactory(HibernateUtil.java:19)
	at com.mkyong.persistence.HibernateUtil.<clinit>(HibernateUtil.java:8)
	at com.mkyong.common.App.main(App.java:11)
Caused by: java.lang.NoClassDefFoundError: org/hibernate/annotations/common/reflection/ReflectionManager
	at com.mkyong.persistence.HibernateUtil.buildSessionFactory(HibernateUtil.java:13)
	... 2 more
Caused by: java.lang.ClassNotFoundException: org.hibernate.annotations.common.reflection.ReflectionManager
	at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
	... 3 more

Solution

You can download the library from Hibernate official website

Or

Add the dependency in Maven’s pom.xml


        <dependency>
		<groupId>hibernate-commons-annotations</groupId>
		<artifactId>hibernate-commons-annotations</artifactId>
		<version>3.0.0.GA</version>
	</dependency>

P.S You may need to include the JBoss repository in order to download the Hibernate common annotation library.


<repositories>
    <repository>
      <id>JBoss repository</id>
      <url>http://repository.jboss.com/maven2/</url>
    </repository>
  </repositories>

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
4 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Hibernate Learner
11 years ago

java.lang.NullPointerException
at org.hibernate.cfg.OneToOneSecondPass.doSecondPass(OneToOneSecondPass.java:135)


SEVERE: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sessionFactory’ defined in ServletContext resource [/WEB-INF/classes/config/database/hibernateSessionFactory.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
…….
…….
Caused by: java.lang.NullPointerException
at org.hibernate.cfg.OneToOneSecondPass.doSecondPass(OneToOneSecondPass.java:135)

I had to replace hibernate-annotations version from 3.2.0ga to 3.3.0.ga

Then I started getting

org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sessionFactory’ defined in ServletContext resource
[/WEB-INF/classes/config/database/hibernateSessionFactory.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/hibernate/annotations/common/reflection/ReflectionManager
…..
…..
Caused by: java.lang.NoClassDefFoundError: org/hibernate/annotations/common/reflection/ReflectionManager

I had to add hibernate commons dependency

org.hibernate
hibernate-commons-annotations
3.2.0.Final

This can be found in the below repository

Central repository
http://repo1.maven.org/maven2

After this Issue was resolved I started getting this error..

Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.(Z)V

Caused by: java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.(Z)V

Was getting this issue because of having different versions of asm jars.
There was asm.jar conflict…
mvn dependency:tree -Dverbose -Dincludes=asm.. command helped to find out.. the jar conflict.
[INFO] mywebapp:mywebapp:war:0.0.1-SNAPSHOT
[INFO] +- org.hibernate:hibernate-annotations:jar:3.3.0.ga:compile
[INFO] | \- org.hibernate:hibernate:jar:3.2.1.ga:compile
[INFO] | +- asm:asm-attrs:jar:1.5.3:compile
[INFO] | \- (asm:asm:jar:1.5.3:compile – omitted for conflict with 3.1)
[INFO] +- cglib:cglib:jar:2.2:compile
[INFO] | \- (asm:asm:jar:3.1:compile – omitted for duplicate)
[INFO] \- asm:asm:jar:3.1:compile
[INFO
org.hibernate-3.2.1 dependency was looking for asm- 1.5.3 jar
and cglib-2.1 dependency was looking for asm-3.1..

I was missing the asm 3.1 jar dependency that was required for cglib

Hope this information would be useful for some one..

Jomcy
4 years ago

my hibernate version is 3.6.8.final and commons annotations is 3.2.0.final and i have this exception.
Caused by: java.lang.ClassNotFoundException: org.hibernate.annotations.common.reflection.ReflectionManager
Can I get some help on this.

Lebron Jameeson
9 years ago

Crystal Clear ! Thx.

Rauni Lillemets
10 years ago

Thank You!