ibatis報列名無效的一個異常分析

NO IMAGE
Caused by: org.springframework.jdbc.UncategorizedSQLException: SqlMapClient operation; uncategorized SQLException for SQL []; SQL state [null]; error code [0]; 列名無效; nested exception is java.sql.SQLException: 列名無效
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:212)
at org.springframework.orm.ibatis.SqlMapClientTemplate.executeWithListResult(SqlMapClientTemplate.java:249)
at com.asc.alibaba.orm.ibatis.SqlMapClientTemplate.queryForList(SqlMapClientTemplate.java:65)
at com.asc.alibaba.orm.ibatis.SqlMapClientTemplate.queryForList(SqlMapClientTemplate.java:47)
at com.asc.alibaba.orm.ibatis.AbstractDaoRouter.query(AbstractDaoRouter.java:66)
at com.asc.alibaba.orm.ibatis.AbstractDaoRouter.query(AbstractDaoRouter.java:175)
at com.alibaba.click.service.app.impl.AppServiceImpl.getUserApps(AppServiceImpl.java:52)
at com.alibaba.click.web.module.screen.app.AppList.execute(AppList.java:38)
at com.alibaba.click.web.module.screen.app.AppList$$FastClassByCGLIB$$be3cb533.invoke(<generated>)
at net.sf.cglib.reflect.FastMethod.invoke(FastMethod.java:53)
at com.alibaba.citrus.service.moduleloader.impl.adapter.MethodInvoker.invoke(MethodInvoker.java:72)
at com.alibaba.citrus.service.moduleloader.impl.adapter.DataBindingAdapter.execute(DataBindingAdapter.java:37)
at com.alibaba.citrus.turbine.pipeline.valve.PerformScreenValve.performScreenModule(PerformScreenValve.java:100)
... 48 more
Caused by: java.sql.SQLException: 列名無效
at com.asc.alibaba.dao.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:234)
at com.asc.alibaba.dao.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessionImpl.java:42)
at com.asc.alibaba.orm.ibatis.SqlMapClientTemplate$2.doInSqlMapClient(SqlMapClientTemplate.java:70)
at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:209)

ibatis的配置:

  <resultMap id="App_ResultMap" class="com.alibaba.click.bean.App" >
<result column="ID" property="id" jdbcType="INTEGER" />
<result column="APPNAME" property="appname" jdbcType="VARCHAR" />
<result column="USER_ID" property="userId" jdbcType="INTEGER" />
<result column="STATUS" property="status" jdbcType="CHAR" />
<result column="OWNER" property="owner" jdbcType="VARCHAR" />
<result column="SYNC_TYPE" property="syncType" jdbcType="VARCHAR" />
<result column="CREATE_TIME" property="createTime" />
<result column="MODIFY_TIME" property="modifyTime" />
<result column="LAST_SYNC_TIME" property="lastSyncTime" />
<result column="USERNAME" property="userName" jdbcType="VARCHAR" />
<result column="DW_CLICK_URL" property="dwClickUrl"  jdbcType="VARCHAR"/>
<result column="DW_EXPOSURE_URL" property="dwExposureUrl" jdbcType="VARCHAR" />
</resultMap>
<!-- 查詢 -->
<select id="query" resultMap="App_ResultMap" parameterClass="java.util.Map" >
select CK_APP.ID, CK_APP.APPNAME, CK_APP.USER_ID, CK_APP.STATUS, CK_APP.OWNER,
CK_APP.CREATE_TIME, CK_APP.MODIFY_TIME, CK_APP.LAST_SYNC_TIME,
wpf_user.USERNAME,CK_APP.DW_CLICK_URL,CK_APP.DW_EXPOSURE_URL
from 
CK_APP, wpf_user
where
<!--  wpf_user.USER_ID=#userId# AND -->
CK_APP.STATUS != '0' AND
CK_APP.USER_ID = wpf_user.USER_ID <!-- AND
CK_APP.ID in
<iterate open="(" close=")" conjunction="," property="appIdList">  
#appIdList[]#
</iterate>  -->
</select>

這裡query的select語句查詢出來的少了一個resultmap的一個欄位 <result column=”SYNC_TYPE” property=”syncType” jdbcType=”VARCHAR” />,所以報列名無效,

 

在下面的兩個類裡面會對查詢結果根據resultmap反射到對應的bean裡進行處理,可以檢視對應的原始碼進行深入瞭解: