You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by "Fabricio M. Sanchez" <fa...@pstonline.co.uk> on 2005/10/11 16:27:12 UTC

MySQL Date Conversions using resultMap

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
 


SOLVED: MySQL Date Conversions using resultMap

Posted by "Fabricio M. Sanchez" <fa...@pstonline.co.uk>.
Thank you very much!!! 

I've renamed the methods so there is no more overloading taking place and
it's picking the correct one!

Fabricio





-----Original Message-----
From: larry.meadors@gmail.com [mailto:larry.meadors@gmail.com] On Behalf Of
Larry Meadors
Sent: 11 October 2005 15:40
To: user-java@ibatis.apache.org
Subject: Re: MySQL Date Conversions using resultMap


Do not name two properties with the same name using different types, this
will cause problems in almost every tool that works with beans.

If you want a string version, call it expiryDateString or something else.

Polymorphic properties are a bad idea.

Larry


On 10/11/05, Fabricio M. Sanchez <fa...@pstonline.co.uk> wrote:
> 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
>
>
>

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

-- 
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
 


Re: MySQL Date Conversions using resultMap

Posted by Larry Meadors <lm...@apache.org>.
Do not name two properties with the same name using different types,
this will cause problems in almost every tool that works with beans.

If you want a string version, call it expiryDateString or something else.

Polymorphic properties are a bad idea.

Larry


On 10/11/05, Fabricio M. Sanchez <fa...@pstonline.co.uk> wrote:
> 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
>
>
>

Re: MySQL Date Conversions using resultMap

Posted by Jeff Butler <je...@gmail.com>.
My best guess is that having overloaded setters breaks the introspection -
this is why you're having strange behavior. This is also an issue with
Struts' form beans - overloaded setters breaks in that case too. Best to
pick one and go with it.
 Jeff Butler

 On 10/11/05, Fabricio M. Sanchez <fa...@pstonline.co.uk> wrote:
>
> 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
>
>
>