简体   繁体   English

休眠会话未创建

[英]Hibernate session not getting created

I am trying to a run an application with Hibernate annotation. 我正在尝试运行带有Hibernate批注的应用程序。 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. 我在lib中有cglib jar。 my java_home is set as follows --- export JAVA_HOME=/usr/jdk1.6.0_18/ 我的java_home设置如下--export JAVA_HOME = / usr / jdk1.6.0_18 /

Please Help I'm struggling with this for a long time. 请帮助我为此困扰了很长时间。

Thanks, Aditya 谢谢,Aditya

If you have that JAR in your WEB-INF/lib, perhaps it's the wrong version. 如果您的WEB-INF / lib中包含该JAR,则可能是错误的版本。 I'd open the JAR and make sure that the class in question is indeed contained inside as well. 我将打开JAR并确保所涉及的类确实也包含在其中。

You don't appear to be relying on a CLASSPATH environment variable. 您似乎并不依赖CLASSPATH环境变量。 That's good, because Tomcat ignores it completely. 很好,因为Tomcat完全忽略了它。 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. 您的JAR必须位于Web上下文的WEB-INF / lib或服务器的/ lib中,以便Tomcat类加载器找到它们。

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

You need to have ASM in the runtime classpath. 您需要在运行时类路径中具有ASM As you're running a webapplication, it needs to be in /WEB-INF/lib . 运行Web应用程序时,它必须位于/WEB-INF/lib It's usually already included in the download pack you got from Hibernate. 它通常已经包含在您从Hibernate获得的下载包中。 Copy it to the runtime classpath. 将其复制到运行时类路径。

Thanks a lot everyone! 非常感谢大家! The problem was the default version in Eclipse was different from the JAVA_HOME path. 问题是Eclipse中的默认版本与JAVA_HOME路径不同。 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. 非常感谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM