ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Fabricio M. Sanchez" <fabri...@pstonline.co.uk>
Subject MySQL Date Conversions using resultMap
Date Tue, 11 Oct 2005 14:32:30 GMT
Hi there,

I have 2 DATE fields on a MySQL table: 'expiry_date' and 'dispatched' that
are identical (apart from their names). They have a default value of NULL
and can be NULL (obviously).

They map to a java class that defines methods for both of them using
parameters String and Date, thus:

public void setExpiryDate( String date ) { System.out.println( "String: " +
date ); }
public void setExpiryDate( java.util.Date date ) { System.out.println(
"Date: " + date ); }

public void setDispatched( String date ) { System.out.println( "String: " +
date ); }
public void setDispatched( java.util.Date date ) { System.out.println(
"Date: " + date ); }

This is my resultMap:
<resultMap id="result-map" class="MyDate">
  <result property="expiryDate" column="expiry_date" nullValue="1900/01/01
00:00:00"/>
  <result property="dispatched" column="dispatched"  nullValue="1900/01/01
00:00:00"/>
</resultMap>

This is my query:
<select id="get-list" resultMap="result-map">
  SELECT *
  FROM MyTable
</select>


For some reason expiry_date always gets mapped using the String version of
setExpiryDate(), and dispatched uses the Date version of setDispatched(). If
I try to set the javaType to anything other than the above (say if I try and
force expiry_date as a java.util.Date), then I get a:

com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in mypath/sql-map.xml.
--- The error occurred while applying a result map.
--- Check the result-map.
--- The error happened while setting a property on the result object.
--- Cause: com.ibatis.common.exception.NestedRuntimeException: Error setting
pro
perties of '2285'.  Cause: java.lang.IllegalArgumentException: argument type
mis
match
Caused by: java.lang.IllegalArgumentException: argument type mismatch
Caused by: com.ibatis.common.exception.NestedRuntimeException: Error setting
pro
perties of '2285'.  Cause: java.lang.IllegalArgumentException: argument type
mis
match
Caused by: java.lang.IllegalArgumentException: argument type mismatch
Press any key to continue...


I have no idea why they would be treated differently if they seem identical.
I want to be able to convert both of them to a java.util.Date. Any ideas?

Thank you!

Fabricio

-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.344 / Virus Database: 267.11.14/128 - Release Date: 10/10/2005
 


Mime
View raw message