Ibatis报错Cause: net.sf.cglib.beans.BulkBeanExceptio

今天有个表用ibaits查询,表结构以下html

CREATE TABLE `matrix_library_temp` (
  `id` bigint(20) NOT NULL COMMENT '主键',
  `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '建立时间',
  `gmt_modified` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '修改时间',
  `temp_author_emp_id` varchar(64) DEFAULT NULL COMMENT '做者的工号',
  `temp_author_nickname` varchar(256) DEFAULT NULL COMMENT '做者的名字',
  `temp_article_title` varchar(1024) DEFAULT NULL COMMENT '临时文章的内容',
  `temp_plain_text` text COMMENT '文章的纯文本内容',
  `temp_content_text` text COMMENT '文章的带格式的文本内容',
  `temp_html_text` text COMMENT '文章的html格式的内容',
  `temp_save_id` varchar(256) DEFAULT NULL COMMENT '单页面修改的惟一标识',
  `temp_logic_deleted` int(11) DEFAULT '0' COMMENT '标识是否显示到草稿列表中',
  PRIMARY KEY (`id`)
)

ibatis的查询语句以下java

<select id="getRecoverNoteList" parameterClass="java.util.HashMap" resultClass="miserTempDO">
    select
    id,
    gmtCreate,
    gmtModififed,
    tempAuthorEmpId,
    tempAuthorNickname,
    tempNoteTitle,
    tempPlainText,
    tempContentText,
    tempHtmlText
    from (
    select
    GROUP_CONCAT( DISTINCT temp_save_id ),
    id as id,
    gmt_create as gmtCreate,
    gmt_modified as gmtModififed,
    temp_author_emp_id as tempAuthorEmpId,
    temp_author_nickname as tempAuthorNickname,
    temp_note_title as tempNoteTitle,
    '' as tempPlainText,
    '' as tempContentText,
    '' as tempHtmlText,
    temp_save_id as tempSaveId
    from matrix_miser_temp WHERE temp_logic_deleted = 0
    <dynamic>
        <isNotNull property="auhtorEmpId" prepend="and">
            temp_author_emp_id=#auhtorEmpId#
        </isNotNull>
        <isNotNull property="id" prepend="and">
            id=#id#
        </isNotNull>
    </dynamic>
    ) t order by id desc
</select>


理论上查询语句会把数据映射成对应的DO类,DO类实现以下sql

public class MiserTempDO {

    private int id;
    private String tempNoteTitle;
    private String tempPlainText;
    private String tempContentText;
    private String tempHtmlText;
    private Date gmtCreate;
    private Date gmtModififed;
    private String tempAuthorEmpId;
    private String tempAuthorNickname;
     
    //getter and setter...   
 }

数据查询没有问题,可是用ibatis调用的时候就报错shell

--- The error occurred in ibatis/Miser.xml.  
--- The error occurred while applying a result map.  
--- Check the miser.getRecoverNoteList-AutoResultMap.  
--- The error happened while setting a property on the result object.  
--- Cause: net.sf.cglib.beans.BulkBeanException
com.ibatis.common.jdbc.exception.NestedSQLException:   
--- The error occurred in ibatis/Miser.xml.  
--- The error occurred while applying a result map.  
--- Check the miser.getRecoverNoteList-AutoResultMap.  
--- The error happened while setting a property on the result object.  
--- Cause: net.sf.cglib.beans.BulkBeanException
	at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:204)
	at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryForList(MappedStatement.java:139)


网上也有相似的报错,缘由是数据库中number字段是nullable的,查询的时候转型的时候错了。数据库

网上的解决方案是再返回中配置为空的时候进行nullvalue处理app

<result property="orders" column="ORDERS" javaType="java.lang.Integer" jdbcType="number" nullValue="0" />

可是我没有配置resultmap因此也不想用这样的方案来解决,spa

首先数据库中是没有数据的,其中只有id是不为空的,而且没有默认值,难道是这里出错了?code

接下来再看DO中id是int型的,难道是空值转int的时候错了?xml

尝试把DO中int改为Integer,问题解决。htm

相关文章
相关标签/搜索