`
topcat
  • 浏览: 282497 次
  • 性别: Icon_minigender_1
  • 来自: 湖北武汉
社区版块
存档分类
最新评论

关于ibatis出现AutoResultMap错误的问题

    博客分类:
  • java
阅读更多

近日开发中用到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 total
	from 
		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 会在每次查询的时候内省查询结果来设置元数据,来保证返回恰当的结果。这个属性会造成一定的性能损失,所以要谨慎使用,只在你需要的时候使用--查询列发生变化

分享到:
评论
3 楼 KG1898 2012-09-13  
谢谢,这问题让我搞了一整天都快崩溃了。。。
2 楼 jqs1124 2012-08-02  
让我搞了一个中午,刚开始以后是缓存问题,谢谢。。。
1 楼 rubyol 2009-01-06  
谢谢,今天在客户的服务器上遇到啦@!@

相关推荐

Global site tag (gtag.js) - Google Analytics