首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java相关 >

--- Cause: java.sql.SQLException: 列名无效

2011-12-11 
关于Ibatis的一个问题,求解答typeAlias aliasuserVOtypecom.test.userVO /resultMap iduserVOR

关于Ibatis的一个问题,求解答
<typeAlias alias="userVO"type="com.test.userVO" />

<resultMap id="userVOResult" class="userVO">


<result property="code" column="fcode" />

<result property="name" column="fname" />

<result property="birthday" column="fbirthday" />

<result property="value" column="fvalue" />



</resultMap>


<select id="sqlQuery1" parameterClass="java.util.Date"
resultMap="userVOResult">

select fcode,fname,fbirthday,fvalue
from t_userwherefbirthday = #fbirthday#
</select>

  <select id="sqlQuery2" parameterClass="java.util.Date"
resultMap="userVOResult">

select fcode,fbirthday,fvalue
from t_userwherefbirthday = #fbirthday#
</select>

在sqlQuery1中定义了返回的结果用resultMap来映射,这样是没问题的,因为sqlQuery1中所有的字段都在resultMap有定义,
但是用sqlQuery2查询就出错了,报错信息如下:(sqlQuery2中没有查name字段,但在resultMap有定义,)
--- Check the result mapping for the 'name' property.  
  --- Cause: java.sql.SQLException: 列名无效
Caused by: java.sql.SQLException: 列名无效

是不是在sql中定义的所有字段在resultMap都必须定义?
如果是上面这种情,其实查询的结果是一样,可是可能会少一些字段,这种情况我就一定要定义2个resultMap嘛?


[解决办法]
select fcode,fbirthday,fvalue,name nullfrom t_user where fbirthday = #fbirthday#

热点排行