使用Hibernate框架下的一些错误

错误一:错误信息:

Exception in thread "main" java.lang.NoClassDefFoundError: org/dom4j/DocumentException

   at com.lyb.hibernate.CreateDB.main(CreateDB.java:9)

解决办法:

缺少相应的JAR包

一般情况下引入dom4j-1.6.1.jar包即可

dom4j-1.6.1.jar http://pan.baidu.com/s/1mgqXH12


错误二:错误信息:

Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory

   at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:152)

   at com.lyb.hibernate.CreateDB.main(CreateDB.java:9)

解决办法:

缺少相应的JAR包

引入slf4j-api-1.5.2.jar

slf4j-api-1.5.2.jar http://pan.baidu.com/s/1o6xFmzg


错误三:错误信息:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".

SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder

   at org.slf4j.LoggerFactory.<clinit>(LoggerFactory.java:60)

   at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:152)

   at com.lyb.hibernate.CreateDB.main(CreateDB.java:9)

解决办法:

缺少相应的JAR包

引入slf4j-log4j12-1.5.2.jar

slf4j-log4j12-1.5.2.jar http://pan.baidu.com/s/1sjp1AKd


错误四:错误信息:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Level

   at org.slf4j.LoggerFactory.<clinit>(LoggerFactory.java:60)

   at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:152)

   at com.lyb.hibernate.CreateDB.main(CreateDB.java:9)

解决办法:

缺少相应的JAR包

引入log4j.jar

log4j.jar http://pan.baidu.com/s/1pJHpZJH


错误五:错误信息:

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).

log4j:WARN Please initialize the log4j system properly.

解决办法:


这是log4j警告,一般可以不用理会,错误原因一般是数据表的主键约束出现错误,可以配置log4j.properties控制日志信息输送的目的地,即可避免log4j警告

在src目录下新建log4j.properties文件,内容如下

log4j.rootLogger=WARN,stdout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender

log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

log4j.appender.stdout.layout.ConversionPattern=%d %p[%c]-%m%n


错误六:错误信息:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/collections/map/LRUMap

   at org.hibernate.util.SimpleMRUCache.init(SimpleMRUCache.java:71)

   at org.hibernate.util.SimpleMRUCache.<init>(SimpleMRUCache.java:55)

   at org.hibernate.util.SimpleMRUCache.<init>(SimpleMRUCache.java:50)

   at org.hibernate.engine.query.QueryPlanCache.<init>(QueryPlanCache.java:65)

   at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:182)

   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1341)

   at com.lyb.hibernate.InsertProduct.main(InsertProduct.java:13)

解决办法:

这里要求的LRUMap.class并不在 org/apache/commons/collections/map/目录中,因此下载commons-collection-3.1jar即可解决问题


引入commons-collections-3.1.jar

commons-collections-3.1.jar http://pan.baidu.com/s/1eQ8KRQE


错误七:错误信息:

Exception in thread "main" org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]

   at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:110)

   at org.hibernate.tuple.entity.EntityTuplizerFactory.constructDefaultTuplizer(EntityTuplizerFactory.java:135)

   at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init>(EntityEntityModeToTuplizerMapping.java:80)

   at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:323)

   at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:456)

   at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:131)

   at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:84)

   at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:267)

   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1341)

   at com.lyb.hibernate.InsertProduct.main(InsertProduct.java:13)

Caused by: java.lang.reflect.InvocationTargetException

   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

   at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)

   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)

   at java.lang.reflect.Constructor.newInstance(Constructor.java:513)

   at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:107)

   ... 9 more

Caused by: java.lang.NoClassDefFoundError: javassist/util/proxy/MethodFilter

   at org.hibernate.bytecode.javassist.BytecodeProviderImpl.getProxyFactoryFactory(BytecodeProviderImpl.java:49)

   at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactoryInternal(PojoEntityTuplizer.java:208)

   at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:186)

   at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:151)

   at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:78)

   ... 14 more


解决办法:

缺少相应的JAR包

引入javassist.jar

javassist.jar http://pan.baidu.com/s/1eQq3Vvs



错误八:错误信息:


Exception in thread "main" org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1

   at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:85)

   at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:70)

   at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:90)

   at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)

   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)

   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)

   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:168)

   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)

   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)

   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1028)

   at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:366)

   at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)

   at com.lyb.hibernate.UpdateProduct.main(UpdateProduct.java:36)

解决办法:一般是数据库在进行数据更新时出现该错误,解决办法就是仔细查看之前插入的数据以及即将进行更新的数据,查看是否有字段不同或者数据类型出现错误。


你可能感兴趣的:(Hibernate,jar包,错误总结,异常解决)