论两个关于*.hbm.xml配置异常的解决(转)
2010-04-27 10:37
295 查看
论两个关于*.hbm.xml配置异常的解决(转)
最近在做一个小的web程序时,遇到了一些小问题,在经过小弟的一番努力后都一一化解了,欣喜之余就想把这些解决心得择取一二与大家共享。这些问题都比较初级,高手就不必看了,以免浪费时间,呵呵。
异常1:*.hbm.xml 配置文件中<id>元素配置异常
抛出异常描述:
org.springframework.orm.hibernate3.HibernateSystemException: ids for this cla
ss must be manually assigned before calling save(): com.ebupt.ncsp.assist.ser
vice.department.domain.Department; nested exception is org.hibernate.id.Ident
ifierGenerationException: ids for this class must be manually assigned before
calling save(): com.ebupt.ncsp.assist.service.department.domain.Department
org.hibernate.id.IdentifierGenerationException: ids for this class must be ma
nually assigned before calling save(): com.ebupt.ncsp.assist.service.departme
nt.domain.Department
出错或异常原因:
<id>元素配置不正确,<id>元素缺少其子元素<generator></generator>的配置。
解决方法:
<id>元素映射了相应数据库表的主键字段,对其子元素<generator class=””>,其中class的取值可以为increment、identity、sequence、hilo、native……等,更多的可参考hibernate 参考文档,一般取其值为native 。
在配置* .hbm.xml文件时我没有使用自动生成工具,直接手动地配置,这也是我一时粗心,加之对hibernate参考不是很熟,只是依葫芦画瓢,建议大家(新手)多看看参考文档,是很有帮助的。
异常2:*.hbm.xml 配置文件中<id>元素配置异常
抛出异常描述:
org.springframework.orm.hibernate3.HibernateSystemException:exception setting property value with CGLIB(set hibernate.cglib.use-reflection-optimizer=false for more info) setter of com.info.beran.com.SetComCode nested exception is org.
hibernate.
PropertyAccessException: setting property value with CGLIB(set hibernate.cglib.use-reflection-optimizer=false for more info)
出错或异常原因:
1. 数据库表中的字段(一般都是数值型的字段)的类型与配置文件中所配置的类型不一致。
2. 在数据库中,数值型字段的值为空null。
相应的解决:
1. 将该字段在配置文件中的类型修改成一致的类型都为Integer。
2. 因为null不能赋值给原始类型,所以在配置数据库中数值型的字段类型(long、int、tinyint)都映射成对象类型Integer问题就解决了。
其实上述的两个异常在使用自动生成配置文件的工具来映射时是不会遇到的,我在这里举出这两个例子希望对大家能够有所帮助
最近在做一个小的web程序时,遇到了一些小问题,在经过小弟的一番努力后都一一化解了,欣喜之余就想把这些解决心得择取一二与大家共享。这些问题都比较初级,高手就不必看了,以免浪费时间,呵呵。
异常1:*.hbm.xml 配置文件中<id>元素配置异常
抛出异常描述:
org.springframework.orm.hibernate3.HibernateSystemException: ids for this cla
ss must be manually assigned before calling save(): com.ebupt.ncsp.assist.ser
vice.department.domain.Department; nested exception is org.hibernate.id.Ident
ifierGenerationException: ids for this class must be manually assigned before
calling save(): com.ebupt.ncsp.assist.service.department.domain.Department
org.hibernate.id.IdentifierGenerationException: ids for this class must be ma
nually assigned before calling save(): com.ebupt.ncsp.assist.service.departme
nt.domain.Department
出错或异常原因:
<id>元素配置不正确,<id>元素缺少其子元素<generator></generator>的配置。
解决方法:
<id>元素映射了相应数据库表的主键字段,对其子元素<generator class=””>,其中class的取值可以为increment、identity、sequence、hilo、native……等,更多的可参考hibernate 参考文档,一般取其值为native 。
在配置* .hbm.xml文件时我没有使用自动生成工具,直接手动地配置,这也是我一时粗心,加之对hibernate参考不是很熟,只是依葫芦画瓢,建议大家(新手)多看看参考文档,是很有帮助的。
异常2:*.hbm.xml 配置文件中<id>元素配置异常
抛出异常描述:
org.springframework.orm.hibernate3.HibernateSystemException:exception setting property value with CGLIB(set hibernate.cglib.use-reflection-optimizer=false for more info) setter of com.info.beran.com.SetComCode nested exception is org.
hibernate.
PropertyAccessException: setting property value with CGLIB(set hibernate.cglib.use-reflection-optimizer=false for more info)
出错或异常原因:
1. 数据库表中的字段(一般都是数值型的字段)的类型与配置文件中所配置的类型不一致。
2. 在数据库中,数值型字段的值为空null。
相应的解决:
1. 将该字段在配置文件中的类型修改成一致的类型都为Integer。
2. 因为null不能赋值给原始类型,所以在配置数据库中数值型的字段类型(long、int、tinyint)都映射成对象类型Integer问题就解决了。
其实上述的两个异常在使用自动生成配置文件的工具来映射时是不会遇到的,我在这里举出这两个例子希望对大家能够有所帮助
相关文章推荐
- EasyPlayerPro-Win 解决xml配置文件中特殊字符读取异常
- 关于web.xml配置error-page或者springmvc添加自定义异常返回画面,画面没有显示
- 关于电脑误删摸个配置文件导致系统异常的解决方法(知道误删的什么文件)
- 【Bug解决】Spring配置错误:java.io.FileNotFoundException: class path resource [cxd/entity/User.hbm.xml] canno
- 关于hibernate的hibernate.cfg.xml配置文件包含 .hbm.xml配置文件的路径写法
- 关于配置XML的异常分析-Mybatis配置文件
- 关于配置 Spring 全自动的 java.lang.StackOverflowError 异常解决
- Struts2配置时报struts-default.xml:65:72异常的解决方法
- [Struts2异常]关于发生Struts配置异常:Unable to find parent packages struts-default.xml的解决方案
- hibernate两个配置模板(***.hbm.xml;***.cfg.xml)
- 关于Dubbo服务管控的xml配置文件报错的解决办法
- 关于Eclipse启动时报ClassNotFoundException: javax.xml.parsers.SAXParserFactory异常的解决
- 关于在Spring配置特殊bean-分散配置的时候抛出的异常:无法找到元素 'context:component-scan' 的声明 的解决方法
- spring 打入jar包 xml配置路径,加载异常等常见问题解决方法
- 关于xxx.hbm.xml中的配置
- intellij配置hibernate自动生成hbm.xml文件
- 关于Request.QueryString发生异常的解决方法
- 解决tomcat6.0.33 配置SSL时报“No Certificate file specified or invalid file format”异常
- The file cannot be validated as the XML definition 异常解决办法
- enum类型映射到hbm.xml配置文件