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()"是沒有效果的.)