遇到的错误总结

1、在spring 与hibernate 集成时出现下列错误

Exception in thread "main" : Error creating bean with name 'userDAO': Injection of resource dependencies failed; nested exception is : Error creating bean with name 'sessionFactory' defined in class path resource [beans.xml]: Error setting property values; nested exception is : Invalid property 'annotatedClasses' of bean class

[org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Bean property 'annotatedClasses' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

at

org.springframework.context.annotation.CommonAnnotationBeanPos tProcessor.postProcessPropertyValues()

at

org.springframework.beans.factory.support.AbstractAutowireCapa bleBeanFactory.populateBean()

at

org.springframework.beans.factory.support.AbstractAutowireCapa bleBeanFactory.doCreateBean()

at

org.springframework.beans.factory.support.AbstractAutowireCapa bleBeanFactory.createBean()

at

org.springframework.beans.factory.support.AbstractBeanFactory$

1.getObject()

at

org.springframework.beans.factory.support.DefaultSingletonBean Registry.getSingleton() at

org.springframework.beans.factory.support.AbstractBeanFactory. doGetBean()

at

org.springframework.beans.factory.support.AbstractBeanFactory.

getBean()

at

org.springframework.beans.factory.support.DefaultListableBeanF actory.preInstantiateSingletons()

at

org.springframework.context.support.AbstractApplicationContext .finishBeanFactoryInitialization()

at

org.springframework.context.support.AbstractApplicationContext .refresh()

at

org.springframework.context.support.ClassPathXmlApplicationCon text.()

at

org.springframework.context.support.ClassPathXmlApplicationCon text.()

atcom.spring.test.SpringTest.main() Caused by: : Error creating bean with name 'sessionFactory' defined in class path resource [beans.xml]: Error setting property values; nested exception is : Invalid property 'annotatedClasses' of bean class

[org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Bean property 'annotatedClasses' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

at

org.springframework.beans.factory.support.AbstractAutowireCapa bleBeanFactory.applyPropertyValues()

at

org.springframework.beans.factory.support.AbstractAutowireCapa bleBeanFactory.populateBean()

at

org.springframework.beans.factory.support.AbstractAutowireCapa bleBeanFactory.doCreateBean()

at

org.springframework.beans.factory.support.AbstractAutowireCapa

bleBeanFactory.createBean()

at

org.springframework.beans.factory.support.AbstractBeanFactory$

1.getObject()

at

org.springframework.beans.factory.support.DefaultSingletonBean Registry.getSingleton() at

org.springframework.beans.factory.support.AbstractBeanFactory. doGetBean()

at

org.springframework.beans.factory.support.AbstractBeanFactory. getBean()

at

org.springframework.context.annotation.CommonAnnotationBeanPos tProcessor.autowireResource()

at

org.springframework.context.annotation.CommonAnnotationBeanPos tProcessor.getResource()

at

org.springframework.context.annotation.CommonAnnotationBeanPos tProcessor$ResourceElement.getResourceToInject()

at

org.springframework.beans.factory.annotation.InjectionMetadata $InjectedElement.inject()

at

org.springframework.beans.factory.annotation.InjectionMetadata .inject()

at

org.springframework.context.annotation.CommonAnnotationBeanPos tProcessor.postProcessPropertyValues()

... 13 more

Caused by: : Invalid property 'annotatedClasses' of bean class

[org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Bean property 'annotatedClasses' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

at

org.springframework.beans.BeanWrapperImpl.setPropertyValue()

at

org.springframework.beans.BeanWrapperImpl.setPropertyValue()

at

org.springframework.beans.AbstractPropertyAccessor.setProperty Values()

at

org.springframework.beans.AbstractPropertyAccessor.setProperty Values()

at

org.springframework.beans.factory.support.AbstractAutowireCapa bleBeanFactory.applyPropertyValues()

... 26 more

原因是,在选择Session 工程类时,选择的工厂类与PO 映射方式不一致,Hibernate 有两个Session 工厂:

1、LocalSessionFactoryBean :通过XX.hbm.xml 来映射实体类

2、AnnotationSessionFactoryBean :通过注释来映射实体类

选择第一种做Session 工厂时,主要通过以下方式添加PO

选择第二种做Session 工厂时,主要通过以下方式添加PO

com.test.entity.TPerson

2、在往数据库中插入数据时出现以下错误:

Exception in thread "main"

: could not insert:

[com.spring.model.User]

at

org.hibernate.exception.SQLStateConverter.handledNonSpecificEx ception()

at

org.hibernate.exception.SQLStateConverter.convert()

at

org.hibernate.exception.JDBCExceptionHelper.convert()

at

org.hibernate.id.insert.AbstractReturningDelegate.performInser t()

at

org.hibernate.persister.entity.AbstractEntityPersister.insert()

atorg.hibernate.persister.entity.AbstractEntityPersister.in sert()

at

org.hibernate.action.EntityIdentityInsertAction.execute()

atorg.hibernate.engine.ActionQueue.execute()

at

org.hibernate.event.def.AbstractSaveEventListener.performSaveO rReplicate()

at

org.hibernate.event.def.AbstractSaveEventListener.performSave()

at

org.hibernate.event.def.AbstractSaveEventListener.saveWithGene ratedId()

at

org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveW ithGeneratedOrRequestedId()

at

org.hibernate.event.def.DefaultSaveEventListener.saveWithGener atedOrRequestedId()

at

org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entit yIsTransient() at

org.hibernate.event.def.DefaultSaveEventListener.performSaveOr Update()

at

org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSav eOrUpdate()

atorg.hibernate.impl.SessionImpl.fireSave()

atorg.hibernate.impl.SessionImpl.save() atorg.hibernate.impl.SessionImpl.save() atcom.spring.DAOImpl.UserDAOImpl.saveUser()

atcom.spring.service.UserService.saveUserDAO()

atcom.spring.test.SpringTest.main()

Caused by: : Field 'id' doesn't have a default value

atcom.mysql.jdbc.SQLError.createSQLException()

atcom.mysql.jdbc.MysqlIO.checkErrorPacket()

atcom.mysql.jdbc.MysqlIO.checkErrorPacket()

atcom.mysql.jdbc.MysqlIO.sendCommand() atcom.mysql.jdbc.MysqlIO.sqlQueryDirect() atcom.mysql.jdbc.ConnectionImpl.execSQL()

at

com.mysql.jdbc.PreparedStatement.executeInternal()

at

com.mysql.jdbc.PreparedStatement.executeUpdate()

at

com.mysql.jdbc.PreparedStatement.executeUpdate()

at

com.mysql.jdbc.PreparedStatement.executeUpdate()

at

org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpd ate()

at

org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpd ate()

at

org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract()

at

org.hibernate.id.insert.AbstractReturningDelegate.performInser t()

... 18 more

原因是在代码中设置了主键自动增长,而在数据库表中并没有设置主键列自增

3、在spring 与hibernate 集成时出现下列错误

Exception in thread "main" : Error creating bean with name 'userService' defined in file

[E:\software\Myeclipse

10.6\workspace\Spring-11Spring_Hibernate_Transaction\bin\com\spring\service\UserService.class]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError:

org/objectweb/asm/Type

at

org.springframework.beans.factory.support.AbstractAutowireCapa bleBeanFactory.doCreateBean()

at

org.springframework.beans.factory.support.AbstractAutowireCapa bleBeanFactory.createBean()

at

org.springframework.beans.factory.support.AbstractBeanFactory$

1.getObject()

at

org.springframework.beans.factory.support.DefaultSingletonBean Registry.getSingleton() at

org.springframework.beans.factory.support.AbstractBeanFactory. doGetBean()

at

org.springframework.beans.factory.support.AbstractBeanFactory. getBean()

at

org.springframework.beans.factory.support.DefaultListableBeanF actory.preInstantiateSingletons()

at

org.springframework.context.support.AbstractApplicationContext .finishBeanFactoryInitialization()

at

org.springframework.context.support.AbstractApplicationContext .refresh()

at

org.springframework.context.support.ClassPathXmlApplicationCon text.()

at

org.springframework.context.support.ClassPathXmlApplicationCon text.()

atcom.spring.test.SpringTest.main() Caused by: java.lang.NoClassDefFoundError:

org/objectweb/asm/Type

atnet.sf.cglib.core.TypeUtils.parseType() atnet.sf.cglib.core.KeyFactory.() atnet.sf.cglib.proxy.Enhancer.() at

org.springframework.aop.framework.Cglib2AopProxy.createEnhance

r()

at

org.springframework.aop.framework.Cglib2AopProxy.getProxy()

at

org.springframework.aop.framework.ProxyFactory.getProxy()

at

org.springframework.aop.framework.autoproxy.AbstractAutoProxyC reator.createProxy()

at

org.springframework.aop.framework.autoproxy.AbstractAutoProxyC reator.wrapIfNecessary() at

org.springframework.aop.framework.autoproxy.AbstractAutoProxyC reator.postProcessAfterInitialization()

at

org.springframework.beans.factory.support.AbstractAutowireCapa bleBeanFactory.applyBeanPostProcessorsAfterInitialization()

at

org.springframework.beans.factory.support.AbstractAutowireCapa bleBeanFactory.initializeBean()

at

org.springframework.beans.factory.support.AbstractAutowireCapa bleBeanFactory.doCreateBean()

... 11 more

Caused by: :

org.objectweb.asm.Type

at java.net.URLClassLoader$1.run() atjava.security.AccessController.doPrivileged() atjava.net.URLClassLoader.findClass()

atjava.lang.ClassLoader.loadClass() atsun.misc.Launcher$AppClassLoader.loadClass()

atjava.lang.ClassLoader.loadClass() atjava.lang.ClassLoader.loadClassInternal()

... 23 more

解决方法:

把Hibernate 的cglib.jar 换成spring 的

cglib.jar(com.springsource.net.sf.cglib-2.2.0.jar)

1、在spring 与hibernate 集成时出现下列错误

Exception in thread "main" : Error creating bean with name 'userDAO': Injection of resource dependencies failed; nested exception is : Error creating bean with name 'sessionFactory' defined in class path resource [beans.xml]: Error setting property values; nested exception is : Invalid property 'annotatedClasses' of bean class

[org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Bean property 'annotatedClasses' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

at

org.springframework.context.annotation.CommonAnnotationBeanPos tProcessor.postProcessPropertyValues()

at

org.springframework.beans.factory.support.AbstractAutowireCapa bleBeanFactory.populateBean()

at

org.springframework.beans.factory.support.AbstractAutowireCapa bleBeanFactory.doCreateBean()

at

org.springframework.beans.factory.support.AbstractAutowireCapa bleBeanFactory.createBean()

at

org.springframework.beans.factory.support.AbstractBeanFactory$

1.getObject()

at

org.springframework.beans.factory.support.DefaultSingletonBean Registry.getSingleton() at

org.springframework.beans.factory.support.AbstractBeanFactory. doGetBean()

at

org.springframework.beans.factory.support.AbstractBeanFactory.

getBean()

at

org.springframework.beans.factory.support.DefaultListableBeanF actory.preInstantiateSingletons()

at

org.springframework.context.support.AbstractApplicationContext .finishBeanFactoryInitialization()

at

org.springframework.context.support.AbstractApplicationContext .refresh()

at

org.springframework.context.support.ClassPathXmlApplicationCon text.()

at

org.springframework.context.support.ClassPathXmlApplicationCon text.()

atcom.spring.test.SpringTest.main() Caused by: : Error creating bean with name 'sessionFactory' defined in class path resource [beans.xml]: Error setting property values; nested exception is : Invalid property 'annotatedClasses' of bean class

[org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Bean property 'annotatedClasses' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

at

org.springframework.beans.factory.support.AbstractAutowireCapa bleBeanFactory.applyPropertyValues()

at

org.springframework.beans.factory.support.AbstractAutowireCapa bleBeanFactory.populateBean()

at

org.springframework.beans.factory.support.AbstractAutowireCapa bleBeanFactory.doCreateBean()

at

org.springframework.beans.factory.support.AbstractAutowireCapa

bleBeanFactory.createBean()

at

org.springframework.beans.factory.support.AbstractBeanFactory$

1.getObject()

at

org.springframework.beans.factory.support.DefaultSingletonBean Registry.getSingleton() at

org.springframework.beans.factory.support.AbstractBeanFactory. doGetBean()

at

org.springframework.beans.factory.support.AbstractBeanFactory. getBean()

at

org.springframework.context.annotation.CommonAnnotationBeanPos tProcessor.autowireResource()

at

org.springframework.context.annotation.CommonAnnotationBeanPos tProcessor.getResource()

at

org.springframework.context.annotation.CommonAnnotationBeanPos tProcessor$ResourceElement.getResourceToInject()

at

org.springframework.beans.factory.annotation.InjectionMetadata $InjectedElement.inject()

at

org.springframework.beans.factory.annotation.InjectionMetadata .inject()

at

org.springframework.context.annotation.CommonAnnotationBeanPos tProcessor.postProcessPropertyValues()

... 13 more

Caused by: : Invalid property 'annotatedClasses' of bean class

[org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Bean property 'annotatedClasses' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

at

org.springframework.beans.BeanWrapperImpl.setPropertyValue()

at

org.springframework.beans.BeanWrapperImpl.setPropertyValue()

at

org.springframework.beans.AbstractPropertyAccessor.setProperty Values()

at

org.springframework.beans.AbstractPropertyAccessor.setProperty Values()

at

org.springframework.beans.factory.support.AbstractAutowireCapa bleBeanFactory.applyPropertyValues()

... 26 more

原因是,在选择Session 工程类时,选择的工厂类与PO 映射方式不一致,Hibernate 有两个Session 工厂:

1、LocalSessionFactoryBean :通过XX.hbm.xml 来映射实体类

2、AnnotationSessionFactoryBean :通过注释来映射实体类

选择第一种做Session 工厂时,主要通过以下方式添加PO

选择第二种做Session 工厂时,主要通过以下方式添加PO

com.test.entity.TPerson

2、在往数据库中插入数据时出现以下错误:

Exception in thread "main"

: could not insert:

[com.spring.model.User]

at

org.hibernate.exception.SQLStateConverter.handledNonSpecificEx ception()

at

org.hibernate.exception.SQLStateConverter.convert()

at

org.hibernate.exception.JDBCExceptionHelper.convert()

at

org.hibernate.id.insert.AbstractReturningDelegate.performInser t()

at

org.hibernate.persister.entity.AbstractEntityPersister.insert()

atorg.hibernate.persister.entity.AbstractEntityPersister.in sert()

at

org.hibernate.action.EntityIdentityInsertAction.execute()

atorg.hibernate.engine.ActionQueue.execute()

at

org.hibernate.event.def.AbstractSaveEventListener.performSaveO rReplicate()

at

org.hibernate.event.def.AbstractSaveEventListener.performSave()

at

org.hibernate.event.def.AbstractSaveEventListener.saveWithGene ratedId()

at

org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveW ithGeneratedOrRequestedId()

at

org.hibernate.event.def.DefaultSaveEventListener.saveWithGener atedOrRequestedId()

at

org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entit yIsTransient() at

org.hibernate.event.def.DefaultSaveEventListener.performSaveOr Update()

at

org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSav eOrUpdate()

atorg.hibernate.impl.SessionImpl.fireSave()

atorg.hibernate.impl.SessionImpl.save() atorg.hibernate.impl.SessionImpl.save() atcom.spring.DAOImpl.UserDAOImpl.saveUser()

atcom.spring.service.UserService.saveUserDAO()

atcom.spring.test.SpringTest.main()

Caused by: : Field 'id' doesn't have a default value

atcom.mysql.jdbc.SQLError.createSQLException()

atcom.mysql.jdbc.MysqlIO.checkErrorPacket()

atcom.mysql.jdbc.MysqlIO.checkErrorPacket()

atcom.mysql.jdbc.MysqlIO.sendCommand() atcom.mysql.jdbc.MysqlIO.sqlQueryDirect() atcom.mysql.jdbc.ConnectionImpl.execSQL()

at

com.mysql.jdbc.PreparedStatement.executeInternal()

at

com.mysql.jdbc.PreparedStatement.executeUpdate()

at

com.mysql.jdbc.PreparedStatement.executeUpdate()

at

com.mysql.jdbc.PreparedStatement.executeUpdate()

at

org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpd ate()

at

org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpd ate()

at

org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract()

at

org.hibernate.id.insert.AbstractReturningDelegate.performInser t()

... 18 more

原因是在代码中设置了主键自动增长,而在数据库表中并没有设置主键列自增

3、在spring 与hibernate 集成时出现下列错误

Exception in thread "main" : Error creating bean with name 'userService' defined in file

[E:\software\Myeclipse

10.6\workspace\Spring-11Spring_Hibernate_Transaction\bin\com\spring\service\UserService.class]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError:

org/objectweb/asm/Type

at

org.springframework.beans.factory.support.AbstractAutowireCapa bleBeanFactory.doCreateBean()

at

org.springframework.beans.factory.support.AbstractAutowireCapa bleBeanFactory.createBean()

at

org.springframework.beans.factory.support.AbstractBeanFactory$

1.getObject()

at

org.springframework.beans.factory.support.DefaultSingletonBean Registry.getSingleton() at

org.springframework.beans.factory.support.AbstractBeanFactory. doGetBean()

at

org.springframework.beans.factory.support.AbstractBeanFactory. getBean()

at

org.springframework.beans.factory.support.DefaultListableBeanF actory.preInstantiateSingletons()

at

org.springframework.context.support.AbstractApplicationContext .finishBeanFactoryInitialization()

at

org.springframework.context.support.AbstractApplicationContext .refresh()

at

org.springframework.context.support.ClassPathXmlApplicationCon text.()

at

org.springframework.context.support.ClassPathXmlApplicationCon text.()

atcom.spring.test.SpringTest.main() Caused by: java.lang.NoClassDefFoundError:

org/objectweb/asm/Type

atnet.sf.cglib.core.TypeUtils.parseType() atnet.sf.cglib.core.KeyFactory.() atnet.sf.cglib.proxy.Enhancer.() at

org.springframework.aop.framework.Cglib2AopProxy.createEnhance

r()

at

org.springframework.aop.framework.Cglib2AopProxy.getProxy()

at

org.springframework.aop.framework.ProxyFactory.getProxy()

at

org.springframework.aop.framework.autoproxy.AbstractAutoProxyC reator.createProxy()

at

org.springframework.aop.framework.autoproxy.AbstractAutoProxyC reator.wrapIfNecessary() at

org.springframework.aop.framework.autoproxy.AbstractAutoProxyC reator.postProcessAfterInitialization()

at

org.springframework.beans.factory.support.AbstractAutowireCapa bleBeanFactory.applyBeanPostProcessorsAfterInitialization()

at

org.springframework.beans.factory.support.AbstractAutowireCapa bleBeanFactory.initializeBean()

at

org.springframework.beans.factory.support.AbstractAutowireCapa bleBeanFactory.doCreateBean()

... 11 more

Caused by: :

org.objectweb.asm.Type

at java.net.URLClassLoader$1.run() atjava.security.AccessController.doPrivileged() atjava.net.URLClassLoader.findClass()

atjava.lang.ClassLoader.loadClass() atsun.misc.Launcher$AppClassLoader.loadClass()

atjava.lang.ClassLoader.loadClass() atjava.lang.ClassLoader.loadClassInternal()

... 23 more

解决方法:

把Hibernate 的cglib.jar 换成spring 的

cglib.jar(com.springsource.net.sf.cglib-2.2.0.jar)


相关文章

  • 实习总结:网络维护实习总结范文
  • 这个暑期是短暂而忙碌的,还没有真正感受到假期来临就已经开学了.虽说真正的企业实习只有短暂的两周,但我却感觉这个假期无时无刻不实习:刚放假,忙着做stitp,然后完成社会实践,后来匆匆忙忙回到学校参加数模培训.虽然说有点忙,有点累,但我却从中 ...查看


  • 软件开发心得总结
  • 有感于网盘开发过程 有感于网盘开发过程 .................................................................................................... ...查看


  • 清华学姐给高三学子的学习建议
  • 清华学姐给高三学子的学习建议! Ⅰ[首先树立一些观念]: 1. [高考比的不是脑子,而是手:手熟一切okay, 不熟什么也别谈] 2. [所谓"状元"智商皆极其平庸,他们靠"自信"取胜] 3. [有天 ...查看


  • 9月交警工作总结
  • 工作总结 自2011年12月份参加交警工作至今,我一直恪守交通协管员的职业纪律,严格按照<人民警察法>来要求自己,认真履行一名交通协管员的职责.半年来,我在上级领导和同事们的帮助指导下,通过自己的努力,在思想上.业务工作水平上都 ...查看


  • sql安装中遇到的问题总结
  • 安装Sqlserver2005出现"性能监视器计数器要求"错误解决方法 今天在安装SQL Server 2005(开发版)时(问题的源头是:原来安装的SQL Server 2005 express版本,在安装Vs2010 ...查看


  • 会计信息系统实验报告总结
  • 篇一:u8 会计信息系统 金蝶 实验报告 心得体会 学 生 实 践 报 告 课程名称: 学生学号: 所属院部: (文科类) 会计信息系统 专业班级: 09会计学(3) 0901101087 商学院 指导教师: 郁露露 20 11 --20 ...查看


  • 电算化会计实训个人总结
  • 电算化会计实训个人总结 2012年7月2日--2012年7月13日,我们在A座教学楼的404进行了为期两周的电算化会计实训. 在这次的实训中,我们主要完成了金蝶KIS标准版中从新建帐套.初始化设置.日常业务处理到生成报表.结账的全过程,以及 ...查看


  • 电子系统课程设计结课报告-----红外遥控开关
  • 电子电路课程设计 实验报告 红外遥控开关 小组成员: 自动化0801 郝嘉然 08212005 自动化0801 侯晓鹏 08212006 自动化0801 胡 泊 08212007 自动化0801 宋晓美 08212012 指导教师: 李维敏 ...查看


  • 2010见习班主任工作总结
  • 在本学期的见习班主任工作中,给我很大的启示,作为一个班的领导核心-班主任.除了狠抓班风.班貌的建设,同时,还要组织好,协调好同学之间的矛盾纠纷,深入了解同学的心理状况和思想动机. 对于学生正是长身体,求知识的黄金时代,同时由于生理.心理以及 ...查看


热门内容