ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nils Winkler" <n...@nilswinkler.com>
Subject Re: Custom Type Handler problems
Date Fri, 13 Jan 2006 14:45:39 GMT
The problem I see is that you're using a HashMap as the result class.
The type handling is done based on the data types of the result class'
attributes. HashMap doesn't know anything about String, that's why your
typehandler is not called. Once you define that you want to have String
instances in your map, iBATIS is able to use the typehandler.


On Fri, 13 Jan 2006 14:31:18 +0000 (GMT), "Gareth Moorst"
<gazj2ee@yahoo.co.uk> said:
>  I seem to be having problems with a global type handler (specified in my
>  sqlmap-config.xml) not being called when I don't specifically set the
>  java type or type handler in a resultmap.
> For instance, say I have the following in an sql map:
> <select id="getTariffCodes" resultClass="java.util.HashMap">
> select tar_code, tar_description from tariffs
> </select>
> and the following type handler set in my global config file:
> <typeHandler javaType="java.lang.String"
> callback="com.phones4u.datamanagement.datamodel.ibatis.typehandler.StringTrimTypeHandler"/>
> When I call the select, my global type handler is ignored even though the
> objects returned from the database are of type java.lang.String.
> I can make it work if I add a resultmap as follows:
> <resultMap class="java.util.HashMap" id="tariffCodeResult">
>     <result property="tar_code" javaType="string"/>
>     <result property="tar_description" javaType="string"/>
> </resultMap>
> So it's not really a showstopper, but it was unexpected - is iBatis
> supposed to work like this?
> I'd like to be able to specify the Type Handler to use globally for all
> objects of a type without having to go through and alter all of my simple
> selects - is this possible?
> Cheers,
> Gareth Moorst
> ---------------------------------
> Yahoo! Messenger  NEW - crystal clear PC to PC calling worldwide with
> voicemail 

View raw message