ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gareth Moorst <gazj...@yahoo.co.uk>
Subject Re: Custom Type Handler problems
Date Fri, 13 Jan 2006 16:08:04 GMT
I see...

That's fair enough - 

Thanks to the list for clearing that up for me

Nathan Maves <Nathan.Maves@Sun.COM> wrote: You are correct.  This is done by the property
type.  AFAIK the type handler is not solely based on the result class.  If you have a class
that has nested properties in it then those type will be identified by ibatis and then have
a CTH assigned if need be.



Some day off in the far future you might be able to do something like resultClass="java.util.HashMap<String,String>"
 but this would require java 1.5 and this is in no way supported as of now.




Nathan

On Jan 13, 2006, at 7:59 AM, Gareth Moorst wrote:

It sounds like a very reasonable guess, it's what I thought might be happening - I was just
after confirmation that the type handler invocations is triggered by the property type and
not by the column type.

Any idea where in the iBatis codebase the object types are checked?
I've done a bit of digging, but I haven't found it yet.

Cheers,

"Fullam, Jonathan, ALABS" <jfullam@att.com> wrote:       Gareth,
  
 I'm  not completely sure how Ibatis handles this internally, but my guess is that  because
your resultClass is a HashMap and it takes Objects (not Strings  specifically), the handler
is not getting called.  If you think about it,  the HashMap could contain Integers depending
on what your sql returns.   Possibly, the type check for determing if a type handler should
be called is  occuring before any type conversions for populating the  HashMap.
  
 Hope  I've been helpful.
  
 -Jonathan
    -----Original Message-----
From: Gareth Moorst    [mailto:gazj2ee@yahoo.co.uk]
Sent: Friday, January 13, 2006 9:31    AM
To: user-java@ibatis.apache.org
Subject: Custom Type    Handler problems


    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 

   


---------------------------------
To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre.





		
---------------------------------
Yahoo! Photos – NEW, now offering a quality print service from just 8p a photo.
Mime
View raw message