views:

184

answers:

3

Hi all,

I am trying to a run an application with Hibernate annotation. I am getting the following exception

Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: net.sf.cglib.core.DebuggingClassWriter$1
Exception in thread "main" java.lang.ExceptionInInitializerError
   at tapes.test.validation.SessionUtil.<clinit>(SessionUtil.java:17)
   at java.lang.Class.initializeClass(libgcj.so.90)
   at tapes.test.validation.LuceneSearch.dbFullIndex(LuceneSearch.java:34)
   at tapes.test.validation.LuceneSearch.main(LuceneSearch.java:143)
Caused by: java.lang.NoClassDefFoundError: net.sf.cglib.core.DebuggingClassWriter$1
   at java.lang.Class.initializeClass(libgcj.so.90)
   at net.sf.cglib.core.DebuggingClassWriter.toByteArray(DebuggingClassWriter.java:73)
   at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:26)
   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.<clinit>(Enhancer.java:69)
   at java.lang.Class.initializeClass(libgcj.so.90)
   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:302)
   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:1300)
   at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
   at tapes.test.validation.SessionUtil.<clinit>(SessionUtil.java:14)
   ...3 more
Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.util.TraceClassVisitor not found in gnu.gcj.runtime.SystemClassLoader{urls=[file:/usr/local/tomcat/webapps/SearchDoctors/Webcontent/WEB-INF/classes/,file:/usr/local/tomcat/webapps/SearchDoctors/WEB-INF/lib/ant-1.6.5.jar,file:/usr/local/tomcat/webapps/SearchDoctors/WEB-INF/lib/ant-antlr-1.6.5.jar,file:/usr/local/tomcat/webapps/SearchDoctors/WEB-INF/lib/ant-junit-1.6.5.jar,file:/usr/local/tomcat/webapps/SearchDoctors/WEB-INF/lib/ant-launcher-.....

Here is the code.

public static void  dbFullIndex() throws CorruptIndexException, LockObtainFailedException, IOException{
        try{
            directory = FSDirectory.getDirectory("/home/athreya/luceneindex/docsIndexFile");
            //Index of the User Table--> /home/araghu/aditya/indexFile
            Session session = SessionUtil.getSessionFactory().getCurrentSession();
            if(IndexReader.indexExists(directory)){
                writer = new IndexWriter(directory, new StandardAnalyzer(),true);
                System.out.println("Index exists");
            }
            else{
                writer = new IndexWriter(directory, new StandardAnalyzer(),true);
                System.out.println("Index doesn't Exist");
            }
            session.beginTransaction();
            org.hibernate.Query query = session.createQuery("from Doctors");
            java.util.List docList = query.list();
            session.getTransaction().commit();
            for( int iter=0;iter< docList.size();iter++){
                Doctors docs=(Doctors) docList.get(iter);
                String pkid=docs.getId()+"";
                String indexString= docs.getFirstName()+" "+docs.getMiddleName()+" "+docs.getLastName()+
                " "+docs.getAddress()+" "+docs.getCity()+" "+docs.getHospitalNames()+" "+docs.getSpecialization()+" "
                +docs.getQualification()+" "+docs.getNatProId();
                //String specialString =docs.getSpecialization()+" "+docs.getHospitalNames();
                writer.addDocument(createDoc(indexString,pkid));
                System.out.println("Name ="+ docs.getFirstName());
                //  writer.addDocument(createSpDoc(specialString));
            }
            writer.close();
        }catch(Exception e){
            e.printStackTrace();
        }
    }       

Can anyone please explain me the problem. I have the cglib jar in place in the lib. my java_home is set as follows --- export JAVA_HOME=/usr/jdk1.6.0_18/

Please Help I'm struggling with this for a long time.

Thanks, Aditya

A: 
Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.util.TraceClassVisitor

You need to have ASM in the runtime classpath. As you're running a webapplication, it needs to be in /WEB-INF/lib. It's usually already included in the download pack you got from Hibernate. Copy it to the runtime classpath.

BalusC
Thanks BalusC. I have the asm.jar in /WEB-INF/lib as well as the classpath. Was that you were referring to?
Aditya R
The `/WEB-INF/lib` is part of the webapp's default classpath. However, the classpath **actually** used depends on how you executed the application. You're talking about "application" instead of "webapplication" all the time. How are you executing it?
BalusC
+1  A: 

If you have that JAR in your WEB-INF/lib, perhaps it's the wrong version. I'd open the JAR and make sure that the class in question is indeed contained inside as well.

You don't appear to be relying on a CLASSPATH environment variable. That's good, because Tomcat ignores it completely. Your JARs need to be in either WEB-INF/lib of your web context or the server /lib in order for the Tomcat class loader to find them.

duffymo
I am running this class directly in Eclipse. I had run this code before in another machine. But I am not able to run it now. I'll check the jar once.
Aditya R
A: 

Thanks a lot everyone! The problem was the default version in Eclipse was different from the JAVA_HOME path. I guess this was the problem. Its fine now. If there are any more problems I know where that you guys are there for me. Thanks a lot.

Aditya R