Hibernate Error – Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: org/apache/commons/collections/SequencedHashMap

A common Hibernate’s error, this is caused by the missing dependency library – Apache Common Collection.


Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: org/apache/commons/collections/SequencedHashMap
Exception in thread "main" java.lang.ExceptionInInitializerError
	at com.mkyong.persistence.HibernateUtil.buildSessionFactory(HibernateUtil.java:18)
	at com.mkyong.persistence.HibernateUtil.<clinit>(HibernateUtil.java:8)
	at com.mkyong.common.App.main(App.java:17)
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/collections/SequencedHashMap
	at org.hibernate.mapping.Table.<init>(Table.java:33)
	at org.hibernate.cfg.Mappings.addTable(Mappings.java:165)
	at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:290)
	at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:273)
	at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:144)
	at org.hibernate.cfg.Configuration.add(Configuration.java:669)
	at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:504)
	at org.hibernate.cfg.Configuration.addResource(Configuration.java:566)
	at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1587)
	at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1555)
	at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1534)
	at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1508)
	at org.hibernate.cfg.Configuration.configure(Configuration.java:1428)
	at org.hibernate.cfg.Configuration.configure(Configuration.java:1414)
	at com.mkyong.persistence.HibernateUtil.buildSessionFactory(HibernateUtil.java:13)
	... 2 more
Caused by: java.lang.ClassNotFoundException: org.apache.commons.collections.SequencedHashMap
	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)
	... 17 more

Solution

You can download the library here – http://commons.apache.org/collections/

Or

Add the dependency in Maven’s pom.xml


      <dependency>
		<groupId>commons-collections</groupId>
		<artifactId>commons-collections</artifactId>
		<version>3.2.1</version>
      </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
2 Comment threads
1 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
2 Comment authors
sowjanyaIjimeroHibernate Tutorials | Tutorials Recent comment authors
newest oldest most voted
Ijimero
Guest
Ijimero

I already have the commons collection and commons logging on my class path (as well as on mu WebContent/WEB-INF/lib) folders, but i’m still getting thins error message.

can somenone help me?

sowjanya
Guest
sowjanya

I have return simple hibernate program to insert employee record in Database, I am getting below error..can anyone please tell me solution to get rid of this error..i have commons jar in classpath Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/commons/co llections/SequencedHashMap at org.hibernate.mapping.Table.(Table.java:33) at org.hibernate.cfg.Mappings.addTable(Mappings.java:164) at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBi nder.java:292) at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:275) at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:146) at org.hibernate.cfg.Configuration.add(Configuration.java:385) at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:426 ) at org.hibernate.cfg.Configuration.addResource(Configuration.java:481) at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.jav a:1453) at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.jav a:1421) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1402) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1378) at org.hibernate.cfg.Configuration.configure(Configuration.java:1298) at org.hibernate.cfg.Configuration.configure(Configuration.java:1284) at com.st.hibernate.EmployeeTestCase.main(EmployeeTestCase.java:7) Thanks, Sowjanya

trackback
Hibernate Tutorials | Tutorials

[…] java.lang.NoClassDefFoundError: org/apache/commons/collections/SequencedHashMap […]