今天有個表用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