java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter

Problem

In Hibernate development, it’s common to hits the following error message.


SEVERE: Context initialization failed
org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'sessionFactory' defined in ServletContext resource 
[/WEB-INF/classes/config/database/spring/HibernateSessionFactory.xml]: 
Invocation of init method failed; nested exception is 

Caused by: org.hibernate.HibernateException: 
Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]
	...
	...
Caused by: java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	...
Caused by: java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(I)V
	at net.sf.cglib.core.DebuggingClassWriter.<init>(DebuggingClassWriter.java:47)
	...

Solution

The “Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer” is a generic error message, it may caused by many reasons. So, you have to look at the last line that caused the error.


Caused by: java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter

The main cause is the old asm.jar library e.g ‘asm-1.5.3.jar’, just upgrade the asm library to the most recent version will get rid of the error message. e.g, ‘asm-3.1.jar’.

Reference

  1. ASM library offcial website

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Comments

Leave a Reply

avatar
newest oldest most voted
Afriano
Guest
Afriano

wow thanks mkyong

Leonel
Guest
Leonel

Me salvaste la vida, gracias !!

Sam
Guest
Sam

tried with:

org.hibernate
hibernate
3.2.3.ga

asm
asm-all
3.1

com.sun.corba
glassfish-corba-asm
3.0.0-b004

still getting:

Initial SessionFactory creation failed.java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.(I)V
Exception in thread “main” java.lang.ExceptionInInitializerError
at com.mkyong.persistence.HibernateUtil.buildSessionFactory(HibernateUtil.java:18)
at com.mkyong.persistence.HibernateUtil.(HibernateUtil.java:8)
at com.mkyong.common.App.main(App.java:11)
Caused by: java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.(I)V
at net.sf.cglib.core.DebuggingClassWriter.(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.(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.(AbstractEntityTuplizer.java:135)
at org.hibernate.tuple.entity.PojoEntityTuplizer.(PojoEntityTuplizer.java:55)
at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.(EntityEntityModeToTuplizerMapping.java:56)
at org.hibernate.tuple.entity.EntityMetamodel.(EntityMetamodel.java:295)
at org.hibernate.persister.entity.AbstractEntityPersister.(AbstractEntityPersister.java:434)
at org.hibernate.persister.entity.SingleTableEntityPersister.(SingleTableEntityPersister.java:109)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
at org.hibernate.impl.SessionFactoryImpl.(SessionFactoryImpl.java:226)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
at com.mkyong.persistence.HibernateUtil.buildSessionFactory(HibernateUtil.java:13)
… 2 more

Mushthaq
Guest
Mushthaq

Hi,
I’m using Hibernate with Restful web services. It gives me the above error. But when I tried to change the ASM version, the Jersey is not working. How can I solve this issue

Hoping for a kind response.
Thank you

GHAFFARI El Mehdi
Guest
GHAFFARI El Mehdi

thank you so much, was hitting the wall, but now it’s got solved ;)

fsaldivars
Guest
fsaldivars

if it’s happen on Glassfish V2.2…
you cant try it.
http://tai-dev.blog.co.uk/2010/01/21/nosuchmethoderror-org-objectweb-asm-classwriter-when-deploying-your-app-to-a-new-instance-of-glassfish-v2-1-1-it-looks-like-the-upgraded-fins-are-7849068/
if page it´s no available:

The simple solution is to manually delete the “asm-3.1.jar” file in the /lib/ directory and copy an old version of “asm-.jar” in its place. We simply copied the asm.jar that was included as a dependency in our download of the Hibernate framework.

Mon
Guest
Mon

Thank you!

lightstar41
Guest
lightstar41

Graceful!

Ademir
Guest
Ademir

Awesomeeeeee it really works!! Thanx a lot!!

Duminda
Guest
Duminda

Great it worked for me!
particularly the advice..

The “Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer” is a generic error message, it may caused by many reasons. So, you have to look at the last line that caused the error.

So looked at the last cause by which said…

Caused by: org.hibernate.PropertyNotFoundException: Could not find a getter for person in class springapp.domain.Schooldetails

(but when the source file was checked the propery did exist!!! What’s going on here. I was using hibernate tools from jboss and thought may be there’s some sort of class caching going around and rebuilt the whole project and walla!.. it worked.)

Ibrahim Mustafa
Guest
Ibrahim Mustafa

Thanks for the solution. You saved my day.

Christopher
Guest
Christopher

Thanks, that’s it :)

trackback
Hibernate Tutorials

[…] java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter […]