eclipse 使用Hibernate出错 java.lang.ClassNotFoundException

问题描述

eclipse使用Hibernate出错java.lang.ClassNotFoundException调试了一天了,各位帮帮忙啊出错信息如下:java.lang.NoClassDefFoundError:org/dom4j/DocumentExceptionorg.util.HibernateSessionFactory.rebuildSessionFactory(HibernateSessionFactory.java:57)org.util.HibernateSessionFactory.getSession(HibernateSessionFactory.java:45)org.dao.imp.ChapterDaoImp.getChapterByID(ChapterDaoImp.java:22)org.action.ChapterAction.execute(ChapterAction.java:21)sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)sun.reflect.NativeMethodAccessorImpl.invoke(UnknownSource)sun.reflect.DelegatingMethodAccessorImpl.invoke(UnknownSource)java.lang.reflect.Method.invoke(UnknownSource)HibernateSessionFactory类的代码:packageorg.util;importorg.hibernate.Session;importorg.hibernate.SessionFactory;importorg.hibernate.cfg.Configuration;publicclassHibernateSessionFactory{privatestaticStringCONFIG_FILE_PATH="/hibernate.cfg.xml";privatestaticStringconfigFile=CONFIG_FILE_PATH;//创建一个线程局部保存对象privatestaticfinalThreadLocal<Session>threadLocal=newThreadLocal<Session>();privatestaticConfigurationconfiguration;//=newConfiguration();privatestaticSessionFactorysessionFactory;privateHibernateSessionFactory()throwsException{super();}publicstaticSessiongetSession(){Sessionsession=threadLocal.get();if(session==null||!session.isOpen()){if(sessionFactory==null)rebuildSessionFactory();session=(sessionFactory!=null)?sessionFactory.openSession():null;//将Session对象绑定到当前线程上面threadLocal.set(session);}returnsession;}publicstaticvoidrebuildSessionFactory(){try{configuration=newConfiguration().configure(configFile);//这里出错了。。。。sessionFactory=configuration.buildSessionFactory();}catch(Exceptione){e.printStackTrace();}}publicstaticvoidcloseSession(){Sessionsession=threadLocal.get();threadLocal.set(null);if(session!=null)session.close();}publicstaticConfigurationgetConfiguration(){returnconfiguration;}publicstaticSessionFactorygetSessionFactory(){returnsessionFactory;}publicstaticvoidsetConfigFile(StringconfigFile){HibernateSessionFactory.configFile=configFile;sessionFactory=null;}}

配置文件:<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEhibernate-configurationPUBLIC"-//Hibernate/HibernateConfigurationDTD3.0//EN""http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><hibernate-configuration><session-factoryname="HibernateSessionFactory"><propertyname="hibernate.connection.driver_class">com.microsoft.jdbc.sqlserver.SQLServerDriver</property><propertyname="hibernate.connection.password">123456</property><propertyname="hibernate.connection.url">jdbc:microsoft:sqlserver://localhost;DatabaseName=JavaEECoursework;SelectMethod=cursor</property><propertyname="hibernate.connection.username">sa</property><propertyname="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property><propertyname="hibernate.show_sql">true</property><mappingclass="org.model.Chapter"/></session-factory></hibernate-configuration>

到底哪里错了吖。。。。。各位帮帮忙啊,感激不尽,调试到崩溃了TAT。。。

解决方案

解决方案二:
http://dom4j.sourceforge.net/下载dom4j
解决方案三:
引用1楼的回复:

http://dom4j.sourceforge.net/下载dom4j

谢谢,不过下载了那个包之后又有错误了java.lang.NullPointerExceptionorg.dao.imp.ChapterDaoImp.getChapterByID(ChapterDaoImp.java:23)org.action.ChapterAction.execute(ChapterAction.java:21)sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)sun.reflect.NativeMethodAccessorImpl.invoke(UnknownSource)sun.reflect.DelegatingMethodAccessorImpl.invoke(UnknownSource)

调用HibernateFactory的代码packageorg.dao.imp;importorg.dao.ChapterDao;importorg.hibernate.Query;importorg.hibernate.Session;importorg.hibernate.SessionFactory;importorg.hibernate.Transaction;importorg.model.Chapter;importorg.util.HibernateSessionFactory;publicclassChapterDaoImpimplementsChapterDao{privateSessionFactorysessionFactory;publicvoidsetSessionFactory(SessionFactorysessionFactory){this.sessionFactory=sessionFactory;}publicChaptergetChapterByID(IntegerchapterID){Sessionsession=HibernateSessionFactory.getSession();Transactionts=session.beginTransaction();Queryquery=session.createQuery("fromChapterwhereChapterID=?");query.setParameter(0,chapterID);query.setMaxResults(1);Chapterchapter=(Chapter)query.uniqueResult();ts.commit();HibernateSessionFactory.closeSession();returnchapter;}}

解决方案四:
我也遇到一样的问题!!一起顶!!
解决方案五:
ClassNotFoundException找不到类异常缺少hibernate的jar包或hibernate的jar包与其他包有冲突,看看hibernate*.jar有几个
解决方案六:
Transactionts=session.beginTransaction();session没获取成功。
解决方案七:
session是null,看配置文件

时间: 2024-09-20 05:44:33

eclipse 使用Hibernate出错 java.lang.ClassNotFoundException的相关文章

ECLIPSE插件开发 连接数据库失败 java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

问题描述 在做ECLIPSE插件开发时,连接数据库失败,报java.lang.ClassNotFoundException:com.mysql.jdbc.Driver我知道报这个一般是因为没有引连接数据库驱动包但是我在插件开发项目包里写一个连接数据库的类就能连接上:在插件开发相关的类里写,在调试插件的时候就会报上面的异常请高手帮忙解答一下这个问题,多谢!!! 解决方案 解决方案二:你加上jar不就完了或者你是打包的问题解决方案三:什么叫"插件开发项目包",什么叫"插件开发相关

java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener Maven项目下update maven后Eclipse报错:java.lang.ClassNotFoundException: ContextLoaderL 严重: Error configuring application listener of class org.springframework.web.contex

hibernate-Hibernate异常 java.lang.ClassNotFoundException

问题描述 Hibernate异常 java.lang.ClassNotFoundException 19-Oct-2015 23:24:58.329 SEVERE [http-apr-8080-exec-6] org.apache.catalina.core.StandardWrapperValve.invoke Allocate exception for servlet mvc-dispatcher java.lang.ClassNotFoundException: org.hibernat

java.lang.ClassNotFoundException: org.hibernate.annotations.Entity

问题描述 最近要把hibernate从3.2升级到3.67.更换JAR包之后,报以下错误,但那个entity在hibernate3.jar包里面是有.先谢谢大家!gframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:282)atorg.springframework.web.context.ContextLoader.initWebApplicationContext(Context

JUnit报错:java.lang.ClassNotFoundException: com.mogodb.test.test

最近在使用JUnit做单元测试时,发现新写好的测试类运行总是出错,报找不到类异常. Class not found com.mogodb.test.test java.lang.ClassNotFoundException: com.mogodb.test.test at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Meth

java.lang.ClassNotFoundException: org.apache.catalina.loader.DevLoader

eclipse tomcat报错:org.apache.catalina.loader.DevLoader java.lang.ClassNotFoundException: org.apache.catalina.loader.DevLoader   这个错误是由于在eclipse的项目中配置了 tomcat属性为 active Devloader. 而且tomcat目录下 \Tomcat \conf\Catalina\localhost  xx.xm中有 <Context path="

java.lang.ClassNotFoundException: com.mysql.jdbc.Drive

linux下使用eclipse开发web项目,运行的时候出现 java.lang.ClassNotFoundException: com.mysql.jdbc.Driver,解决办法如下: 1.导入MySQL驱动包: 右键项目-properties-build path 两种方式: (1)Add JARs--需要先把mysql的jar驱动复制到项目目录下,复制项目到别的电脑上的时候驱动会跟着一起走(因为在项目目录下). (2)Add External JARs--不需要将驱动复制到项目目录下,但

web.xm里配置Listener报java.lang.ClassNotFoundException:

问题描述 <listener> <description>在线用户监听器</description> <listener-class>com.leruan.aasimp.listener.OnLineListener</listener-class> </listener> 上面是监听器的配置,com.leruan.aasimp.listener.OnLineListener我的项目里是有的,但是启动tomcat时报如下错误:java

wordcount exception in thread main java.lang.classnotfoundexception:Wordcount

问题描述 版本:hadoop-1.2.1,jdk-1.8.0_45,ubuntu-10.04编写TokenizerMapper.java,IntSumReducer.java,WordCount.java三个文件,1,"cd~/wordcount_01",2,"javac-classpath/home/brian/usr/hadoop/hadoop-1.2.1/hadoop-core-1.2.1.jar:/home/brian/usr/hadoop/hadoop-1.2.1/