异常:net.sf.cglib.beans.BulkBeanException

异常描述:

The error occurred in sqlmap/empdailyreport.xml. 
--- The error occurred while applying a result map. 
--- Check the EmpDailyReport.ReportResult. 
--- The error happened while setting a property on the result object. 
--- Cause: net.sf.cglib.beans.BulkBeanException


resultMap定义:

<resultMap id="ReportResult" class="com.jd.sns.chat.common.domain.empdailyreport.ReportResult">
	<result column="pin" jdbcType="VARCHAR" property="pin" />
	<result column="count" jdbcType="INTEGER" property="count" />
	<result column="orgId" jdbcType="INTEGER" property="orgId" />
</resultMap>


 

ReportResult定义:

package com.jd.sns.chat.common.domain.empdailyreport;
/**
 * 查询统计返回辅助类
 * @author cdlitao1
 * @2012-9-27
 */
public class ReportResult {
	/**
	 * 客服pin
	 */
	private String pin;
	/**
	 * 统计值
	 */
	private int count=0;
	/**
	 * 该统计数据所属pin所在的技能组id
	 * @return
	 */
	private int orgId;
	
	public int getOrgId() {
		return orgId;
	}
	public void setOrgId(int orgId) {
		this.orgId = orgId;
	}
	public String getPin() {
		return pin;
	}
	public void setPin(String pin) {
		this.pin = pin;
	}
	public int getCount() {
		return count;
	}
	public void setCount(int count) {
		this.count = count;
	}
}


 

sql查询语句:

 

<select id="findReceptionNo" parameterClass="ReportProfile" resultMap="ReportResult">
<![CDATA[
	SELECT service AS pin,COUNT(1) AS count,orgId 
	FROM analysis_session 
	WHERE created>=#startTime:VARCHAR# AND created<#endTime:VARCHAR# 
	AND responseTime IS NOT NULL
	GROUP BY service
]]>
</select>


 

 

 

异常原因:

eg 1:sql查询语中返回的字段有NULL值,当映射给int等基本类型时就会出错

解决方案1:resultMap定义映射关系时进行修改-----<result column="orgId" jdbcType="INTEGER" property="orgId" nullvalue="0"/>

方案分析:增加的nullvalue="0"的作用是将字段orgId的返回值中的null替换为0,避免了null与int型属性的映射

eg 2:NULL映射给封装类型Integer时不会出错!!!


注:Integer in = null;对(此in变量实际上也是个java对象)


   int in = null;错!(此in实际仅是java类中的一个属性)


解决方案2:将resultMap映射的java类ReportResult中的属性都定义为封装类,此例中将orgId的类型由int改为Integer,异常解决

方案分析:null值与封装类可以进行映射,而int属于java基本类型,与null映射会出错!

建议:在使用resultMap进行返回值映射时,建议将对应的java类中的属性的类型定义为封装类型,避免此异常

涛小菜20121012

cdlitao1@360buy.com

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值