title: .Getting a java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(Z)V in my spring hibernate application
body: <p>I'm using spring and hibernate in my application. For building REST APIs, Im using jersey and it is a gradle based project. These are dependencies I've specified in build.gradle:</p>
  
  <pre><code>compile 'org.springframework:spring-core:3.2.4.RELEASE',
         'org.springframework:spring-context:3.2.4.RELEASE',
         'org.springframework:spring-web:3.2.4.RELEASE',
         'com.sun.jersey:jersey-server:1.8',
         'com.sun.jersey:jersey-core:1.8',
         'mysql:mysql-connector-java:5.1.26',
         'c3p0:c3p0:0.9.1.2',
         'javax.transaction:jta:1.1',
         'org.hibernate:hibernate:3.2.5.GA',
         'org.hibernate:hibernate-annotations:3.3.1.GA',
         'asm:asm:3.1',
         'cglib:cglib-nodep:2.2',
         'org.springframework:spring-hibernate3:2.0.8',
         'org.hibernate:ejb3-persistence:1.0.2.GA'
  </code></pre>
  
  <p>Even though hibernate version that I've given is 3.2.5, it is downloading 3.2.6 when I build it. When I deploy war to tomcat7, I get java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.(Z)V. Here is the complete stack trace:</p>
  
  <pre><code>org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.&lt;init&gt;(Z)V
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1482)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
  at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:610)
  at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
  at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
  at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)
  at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
  at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4797)
  at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5291)
  at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
  at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
  at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
  at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
  at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:977)
  at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:542)
  at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1462)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:606)
  at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:301)
  at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
  at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
  at org.apache.catalina.manager.ManagerServlet.check(ManagerServlet.java:1445)
  at org.apache.catalina.manager.ManagerServlet.deploy(ManagerServlet.java:677)
  at org.apache.catalina.manager.ManagerServlet.doPut(ManagerServlet.java:435)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
  at org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:108)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
  at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:581)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
  at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
  at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
  at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
  at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
  at java.lang.Thread.run(Thread.java:724)
  Caused by: java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.&lt;init&gt;(Z)V
  at net.sf.cglib.core.DebuggingClassWriter.&lt;init&gt;(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:145)
  at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:117)
  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.&lt;clinit&gt;(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.&lt;init&gt;(AbstractEntityTuplizer.java:135)
  at org.hibernate.tuple.entity.PojoEntityTuplizer.&lt;init&gt;(PojoEntityTuplizer.java:55)
  at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.&lt;init&gt;(EntityEntityModeToTuplizerMapping.java:56)
  at org.hibernate.tuple.entity.EntityMetamodel.&lt;init&gt;(EntityMetamodel.java:302)
  at org.hibernate.persister.entity.AbstractEntityPersister.&lt;init&gt;(AbstractEntityPersister.java:434)
  at org.hibernate.persister.entity.SingleTableEntityPersister.&lt;init&gt;(SingleTableEntityPersister.java:109)
  at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
  at org.hibernate.impl.SessionFactoryImpl.&lt;init&gt;(SessionFactoryImpl.java:226)
  at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1300)
  at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
  at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:805)
  at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:745)
  at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:134)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1541)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1479)
  ... 52 more
  </code></pre>
  
  <p>Here is my applicationContext.xml:</p>
  
  <pre><code>&lt;bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"&gt;
      &lt;property name="driverClass" value="com.mysql.jdbc.Driver"/&gt;
      &lt;property name="jdbcUrl" value="jdbc:mysql://localhost:3306/my_db"/&gt;
      &lt;property name="user" value="coder"/&gt;
  &lt;/bean&gt;
  
  &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"&gt;
      &lt;property name="dataSource" ref="dataSource"/&gt;
      &lt;property name="configLocation"&gt;
          &lt;value&gt;classpath:hibernate.cfg.xml&lt;/value&gt;
      &lt;/property&gt;
      &lt;property name="annotatedClasses"&gt;
          &lt;list&gt;
              &lt;value&gt;com.myprojects.pojos.AppConfig&lt;/value&gt;
          &lt;/list&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>I found in many places that it is caused by asm and they had insisted on using asm-3.1 which I have used but I still get the same error. Unable to narrow down which library is conflicting.</p>
  
  <p>AppConfig class:</p>
  
  <pre><code>package com.appdevapi.appconfig.pojos;
  
  import java.sql.Date;
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.Id;
  import javax.persistence.PrePersist;
  import javax.persistence.PreUpdate;
  import javax.persistence.Table;
  
  @Entity
  @Table(name = "app_config")
  public class AppConfig {
  
    @Id
    @Column(name = "id")
    private int id;
    @Column(name = "name")
    private String name;
    @Column(name = "description")
    private String description;
    @Column(name = "created_time")
    private Date createdTime;
    @Column(name = "updated_time")
    private Date updatedTime;
  
    public AppConfig(String name, String description) {
      this.name = name;
      this.description = description;
    }
  
    public AppConfig(String name) {
      this.name = name;
    }
  
    public AppConfig() {
    }
  
    public int getId() {
      return id;
    }
  
    public void setId(int id) {
      this.id = id;
    }
  
    public String getName() {
      return name;
    }
  
    public void setName(String name) {
      this.name = name;
    }
  
    public String getDescription() {
      return description;
    }
  
    public Date getCreatedTime() {
      return createdTime;
    }
  
    public void setCreatedTime(Date createdTime) {
      this.createdTime = createdTime;
    }
  
    public Date getUpdatedTime() {
      return updatedTime;
    }
  
    public void setUpdatedTime(Date updatedTime) {
      this.updatedTime = updatedTime;
    }
  
    public void setDescription(String description) {
      this.description = description;
    }
  
    @PrePersist
    public void assignCreatedTime() {
      Long curTimestamp = new java.util.Date().getTime();
      this.setCreatedTime(new Date(curTimestamp));
    }
  
    @PrePersist
    @PreUpdate
    public void assignUpdatedTime() {
      Long curTimestamp = new java.util.Date().getTime();
      this.setUpdatedTime(new Date(curTimestamp));
    }
  }
  </code></pre>
  
  <p>Dependencies:</p>
  
  <ul>
  <li>aopalliance-1.0</li>
  <li>antlr-2.7.6</li>
  <li>asm-3.1</li>
  <li>asm-attrs-1.5.3</li>
  <li>c3p0-0.9.1.2</li>
  <li>cglib-2.1_3</li>
  <li>commons-collection-2.1.1</li>
  <li>commons-logging</li>
  <li>dom4j-1.6.1</li>
  <li>ehcache-1.2.3</li>
  <li>ejb3-persistence-1.0.2.GA</li>
  <li>hibernate-3.2.6</li>
  <li>hibernate-annotations-3.3.1.GA</li>
  <li>hibernate-commons-annotations-3.0.0</li>
  <li>jersey-core-1.8</li>
  <li>jerser-server-1.8</li>
  <li>jta-1.1</li>
  <li>mysql-connector-java-5.1.26</li>
  <li>spring-aop-3.2.4.RELEASE</li>
  <li>spring-3.2.4.RELEASE</li>
  <li>spring-core-3.2.4.RELEASE</li>
  <li>spring-expression-3.2.4.RELEASE</li>
  <li>spring-jdbc-3.2.4.RELEASE</li>
  <li>spring-orm-3.2.4.RELEASE</li>
  <li>spring-tx-3.2.4.RELEASE</li>
  <li>spring-web-3.2.4.RELEASE</li>
  </ul>