net.sf.cglib.beans.BulkBeanException 数据列为空,不能set值,报错

net.sf.cglib.beans.BulkBeanException

 SqlMapClient operation; uncategorized SQLException for SQL []; SQL state [null]; error code [0];  
--- The error occurred in com/winclass/cet/persistence/cihui/sql/GlossaryVO.xml. 
--- The error occurred while applying a result map. 
--- Check the GlossaryVO.getThemeByWordName-AutoResultMap. 
--- The error happened while setting a property on the result object. 

net.sf.cglib.beans.BulkBeanException


方法一:

最后通过baidu一下知道了异常Cause: net.sf.cglib.beans.BulkBeanException引起的原因是数据库表中有一个可以为空的列(列的类型是number),当查询的时候由于该列没有值ibtis会用null去初始化该列,但把null类型赋值给number类型的值时,出现如上异常信息。解决方法是找到ibatis配置文件sql-t.xml中的

<resultMap id="result-task-obj" class="Task_Obj">
<result property="year" column="YEAR"/>
</resultMap>


<result property="year" column="YEAR"/>
修改成
<result property="year" column="YEAR" nullValue="0"/>
即当YEAR列对应的值为null时,会用0值初始化year属性(year对应其类中的数据类型是int)。修改后系统运行正常。
数据类型是int、float、double  都可以使用此方法。

方法二:

eg 2:

当时我在猜想会不会跟Bulk这个单词有关?就立马想到是model里面属性值不足以装下resultMap里面某个字段的值,会不会是类型问题?我一看,表里面的是统计失败次数的Integer(Sybase IQ数据库),就把

Java代码 private int calling_answer;    private int calling_drop;    private int called_answer;

private int calling_answer; private int calling_drop;private int called_answer; private int called_drop;
全换成Integer类型了,一调试终于好了!
以后model里面的类型都要设置成封装类型,避免类似的错误  

自己试验得出:

【1】. <resultMap id="ThemeVO" class="ThemeVO">
      <result property="year" column="year" nullValue="0" />
  <result property="yuefeng" column="yuefeng" nullValue="0" />
  <result property="source" column="source" nullValue="0" />
  </resultMap>
     <!-- 单词的相关试题 一道 zhulin 2011-8-27 -->
     <select id="getThemeByWordName" parameterClass="String" resultMap="ThemeVO">
        select * from mv_cet_tiku where QUESTIONS=13 and contains(title, #wordname#)>0 and  rownum < 2
     </select> 

注意:resultMap的id和resultMap的resultMap是一致的

【2】. select NVL(year,0) from mv_cet_tiku where QUESTIONS=13 and contains(title, 'able')>0 and  rownum < 2   

将number的字段nvl一下,运行也成功。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值