Results 1 to 6 of 6

Thread: NoClassDefFoundError ... HibernateProxy

Hybrid View

  1. #1

    Default NoClassDefFoundError ... HibernateProxy

    Hello,

    when deploying my Spring webapp to another Tomcat 5.5 server I get an exception meaning it does not find a Hibernate class. Although it is definitely in the WEB-INF/lib of my webapp. (It runs smoothly on my Tomcat 6 test environment.)

    I assume the Spring libs are loaded BEFORE the hibernate libs and so Spring does not find the proper Hibernate classes to build the "sessionFactory".

    Can I control the jar loading sequence for Tomcat somehow?

    Code:
    2007-07-01 18:36:20,312 [Thread-1] ERROR org.springframework.web.context.ContextLoader - Context initialization failed
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [../applicationContext-db.xml]: Invocation of init method failed; nested exception is net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
    Caused by: 
    net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
    	at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:237)
    	at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
    	at net.sf.cglib.proxy.Enhancer.createClass(Enhancer.java:317)
    	at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:127)
    	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 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:1175)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1145)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:427)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:144)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:276)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:360)
    	at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:241)
    	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:184)
    	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
    	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3729)
    	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4183)
    	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:759)
    	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:739)
    	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524)
    	at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:904)
    	at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:867)
    	at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:474)
    	at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1112)
    	at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:310)
    	at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1021)
    	at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
    	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1013)
    	at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442)
    	at org.apache.catalina.core.StandardService.start(StandardService.java:450)
    	at org.apache.catalina.core.StandardServer.start(StandardServer.java:709)
    	at org.apache.catalina.startup.Catalina.start(Catalina.java:551)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:275)
    	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
    Caused by: java.lang.reflect.InvocationTargetException
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	at net.sf.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:384)
    	at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:219)
    	... 53 more
    Caused by: java.lang.NoClassDefFoundError: org/hibernate/proxy/HibernateProxy
    	at java.lang.ClassLoader.defineClass1(Native Method)
    	at java.lang.ClassLoader.defineClass(Unknown Source)
    	... 59 more

  2. #2
    Join Date
    Aug 2006
    Location
    Now Germany, previously Ukraine
    Posts
    1,546

    Default

    In this case loading sequence does not matter. As soon as class is on classpath it shall be found and loaded. So problem is somewhere else.

    Firstly, I would recheck the class path (yes, you are sure, but check once more anyway).

    Secondly, can it be classloader issue (check if you do not have Spring or jars not only in your lib directory, but e.g. in the shared/lib or common/lib Tomcat directories)?

    Regards,
    Oleksandr

  3. #3

    Default

    I think it has something to do with my cglib, asm and hibernate libs. Something is wrong about that. I tried many combinations of different version of those libraries and everytime I get another exception. Sometimes NoClassDefFoundError (because of asm-CodeVisitor), sometimes NoSuchMethodError.

    I am still working on that ...

  4. #4
    Join Date
    Aug 2006
    Location
    Now Germany, previously Ukraine
    Posts
    1,546

    Default

    Quote Originally Posted by Rapthor View Post
    I think it has something to do with my cglib, asm and hibernate libs. Something is wrong about that. I tried many combinations of different version of those libraries and everytime I get another exception. Sometimes NoClassDefFoundError (because of asm-CodeVisitor), sometimes NoSuchMethodError.

    I am still working on that ...
    Yes, its possible. There is known incompatibility between asm delivered the Spring and delivered with the Hibernate 3.2. This topic was discussed many times, just search Data Access forum. And there shall be JIRA issue(s) devoted to this topic.

    As far as I can remember workaround is to use nodep version of cglib (i.e. version that contains asm with altered package names inside of cglib jar).

    Regards,
    Oleksandr

  5. #5

    Default

    As I tried many combinations of the libs I am now using "cglib-nodep-2.2_beta1" and get the following Exception (NoSuchMethodError):

    Code:
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [../applicationContext-db.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.objectweb.asm.ClassVisitor.visit(IILjava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;)V
    Caused by: 
    java.lang.NoSuchMethodError: org.objectweb.asm.ClassVisitor.visit(IILjava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;)V
    	at net.sf.cglib.core.ClassEmitter.begin_class(ClassEmitter.java:77)
    	at net.sf.cglib.core.KeyFactory$Generator.generateClass(KeyFactory.java:172)
    	at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
    	at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
    	at net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:144)..............
    When using the non-beta version 2.1 of cglib-nodep I get the Exception mentioned above (NoClassDefFoundError "HibernateProxy") even though the hibernate3.jar is in the classpath. (Everything runs fine on Tomcat 6, not on Tomcat 5)

  6. #6
    Join Date
    Aug 2006
    Location
    Now Germany, previously Ukraine
    Posts
    1,546

    Default

    J will suggest once more to make search here and in the Spring JIRA for this issue. It was actively discussed here and bug (or bugs) filed in JIRA, along with some comments and workarounds that I can not remember in all details.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •