Hibernate配置过程可能发生的问题及解决方法
1.问题:Exception in thread "main" java.lang.NoClassDefFoundError: org/dom4j/DocumentException
at HibernateTest.main(HibernateTest.java:14)
方法:添加dom4j.jar(解析hibernate.cfg.xml文件)
2.问题:Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:116)
at HibernateTest.main(HibernateTest.java:14)
方法:添加commons-logging.jar(记录解析过程)
3.问题:Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/collections/SequencedHashMap
方法:添加commons-collections.jar(在解析映射文件时,需要把所有持久化对象的定义放在一个HashMap中)
4.问题:Exception in thread "main" java.lang.NoClassDefFoundError: net/sf/ehcache/CacheException
方法:添加ehcache.jar(高速缓存,提高存取速度)
5.问题:2009-2-22 23:45:40 net.sf.ehcache.config.Configurator configure
警告: No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/F:/MyJava/Hibernate/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
Exception in thread "main" java.lang.NoClassDefFoundError
方法:把ehcache-1.1.jar解压,把其中的ehcache-failsafe.xml改成ehcache.xml。
6.问题:Caused by: java.lang.ClassNotFoundException: net.sf.cglib.transform.impl.InterceptFieldEnabled
方法:添加cglib-full-2.0.02.jar
7.问题:Caused by: java.lang.NoSuchMethodError: net.sf.cglib.proxy.Enhancer.setInterceptDuringConstruction(Z)V
方法:添加cglib-nodep-2.1_3.jar
8.问题:Exception in thread "main" java.lang.NoClassDefFoundError: javax/transaction/Synchronization
方法:添加jta.jar(事务处理)
9.问题:Exception in thread "main" java.lang.NoClassDefFoundError: antlr/ANTLRException
方法:添加antlr-2.7.5h3.jar
10问题:Caused by: java.sql.SQLException: The statement (1) has no open cursor.
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2901)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:773)
方法: <!-- <property name="jdbc.fetch_size">50 </property> -->
把上面这个属性按上面这样注释掉就可以了. (如果mysql-connector的版本早于3.2.1而且服务器的版本早于5.0.3,"setFetchSize()"是没有效果的.)
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/woxueliuyun/archive/2009/02/23/3930335.aspx