六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 60|回复: 0

关于ibatis出现AutoResultMap错误的问题

[复制链接]

升级  14.67%

16

主题

16

主题

16

主题

秀才

Rank: 2

积分
72
 楼主| 发表于 2013-1-27 05:06:09 | 显示全部楼层 |阅读模式
近日开发中用到ibatis在使用的过程中出现了AutoResultMap的错误
配置如下:
<select id="statistic" parameterClass="map" resultClass="java.util.HashMap">    select <isNotNull  property="category">        b.description as descriptionB,    </isNotNull><isNotNull  property="serl">        c.description as descriptionC,    </isNotNull>sum(1) as totalfrom t_es_reginfo a<isNotNull  property="category"><isEqual compareValue="city" property="category">left join t_bs_$category$ b on a.$category$=b.code</isEqual><isNotEqual compareValue="city" property="category">left join t_cd_$category$ b on a.$category$=b.id</isNotEqual></isNotNull><isNotNull  property="serl"><isEqual compareValue="city" property="serl">left join t_bs_$serl$ c on a.$serl$=c.code</isEqual><isNotEqual compareValue="city" property="serl">left join t_cd_$serl$ c on a.$serl$=c.id</isNotEqual></isNotNull>where a.examid=#examid#<isNotNull property="city">and a.city=#city#</isNotNull>group by 1<isNotNull property="category">        ,a.$category$    </isNotNull><isNotNull property="serl">   ,a.$serl$</isNotNull>order by -1<isNotNull property="category">        ,a.$category$    </isNotNull><isNotNull property="serl">    ,a.$serl$</isNotNull>  </select> 由于多次产生的列数可能会不一样,所以当每一次查出来是三列,第二次是两列的话就会报AutoResultMap的错( java.sql.SQLException:   列名无效),经查后发现有个remapResults的属性可以设置为true就可以了,原因如下:
 
在 【statement】, 【select】, 和【procedure】 标签中存在一个可选的属性【remapResults】,默认值是false.如果每次查询的列不定的话,这个属性需要设置为true.为了避免经常的对返回的结果进行内省,iBATIS会记录上一次查询结果的元数据,iBATIS会在每次查询的时候内省查询结果来设置元数据,来保证返回恰当的结果。这个属性会造成一定的性能损失,所以要谨慎使用,只在你需要的时候使用--查询列发生变化
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表