CTOCIO IT专家网

天极传媒 比特网 | 天极网 | IT专家网 | IT商网 | 52PK游戏网 | 手机天极 | IT分众 |
IT专家网搜索

您现在的位置: IT专家网 > Web服务子站 > Java技术

Hibernate配置文件异常的排除

作者: yanglx ,  出处:IT专家网论坛, 责任编辑: 包春林, 
2008-05-14 04:00
  最近在做一个小的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问题就解决了。

  其实上述的两个异常在使用自动生成配置文件的工具来映射时是不会遇到的,我在这里举出这两个例子希望对大家能够有所帮助。

网友评论

笔名 
请您注意:遵守国家有关法律、法规,尊重网上道德,承担一切因您的行为而直接或间接引起的法律责任。    IT专家网友拥有管理笔名和留言的一切权利。
  • 周排行榜
  • 月排行榜

邮件订阅

       
天极服务 | 关于我们 | 网站律师 | 加入我们 | 联系我们 | 广告业务 | 友情链接 | 我要挑错
All Rights Reserved, Copyright 2004-2008, Ctocio.com.cn
渝ICP证B2-20030003号 如有意见请与我们联系 powered by 天极内容管理平台CMS4i