sessionfactory-creation-failed-java-lang-nosuchmethoderror-org-objectweb-asm-classwriter

sessionfactory-creation-failed-java-lang-nosuchmethoderror-org-objectweb-asm-classwriter

If you are using hibnernate and during CRUD operation get belwo error:

Initial SessionFactory creation failed.java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(I)V
Exception in thread "main" java.lang.ExceptionInInitializerError
	at com.javahonk.HibernateUtil.buildSessionFactory(HibernateUtil.java:13)
	at com.javahonk.HibernateUtil.<clinit>(HibernateUtil.java:6)
	at com.javahonk.InsertData.main(InsertData.java:12)
Caused by: java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(I)V
	at net.sf.cglib.core.DebuggingClassWriter.<init>(DebuggingClassWriter.java:47)
	at net.sf.cglib.core.DefaultGeneratorStrategy.getClassWriter(DefaultGeneratorStrategy.java:30)
	at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:24)
	at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
	at net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:144)
	at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:116)
	at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:108)
	at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:104)
	at net.sf.cglib.proxy.Enhancer.<clinit>(Enhancer.java:69)
	at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:117)
	at org.hibernate.proxy.pojo.cglib.CGLIBProxyFactory.postInstantiate(CGLIBProxyFactory.java:43)
	at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:162)
	at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:135)
	at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:55)
	at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init>(EntityEntityModeToTuplizerMapping.java:56)
	at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:295)
	at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:434)
	at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:109)
	at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
	at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:226)
	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
	at com.javahonk.HibernateUtil.buildSessionFactory(HibernateUtil.java:10)
	... 2 more

 

Solution: This happens due to asm jar old library. Upgrate to new version of asm:

  • If you are using MAVEN project add below dependency in your pom.xml file:
<dependency>
		<groupId>asm</groupId>
		<artifactId>asm</artifactId>
		<version>3.1</version>
</dependency>

 

  • If you are using eclipse with lib please add asm-3.1.jar to your lib folder and include in your class path.
  • This should resolve the above issue.

sessionfactory-creation-failed-java-lang-nosuchmethoderror-org-objectweb-asm-classwriter

Leave a Reply

Your email address will not be published. Required fields are marked *