You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-cs@ibatis.apache.org by EXT / ASTEK MOUSSON Nicolas <ex...@sncf.fr> on 2007/09/28 17:29:51 UTC

RE : nullValue in ResultMap simply does not work

I think you miss something, because all works fine with the inline syntax for null values...

Example of SQL Insert :

		INSERT INTO TABLEXXX
            (
	          Column1,
                Column2
            )
            VALUES
            (
                #Id#,
                #MyDate:DateTime:01/01/0001 00:00:00#
            )

	Then if you pass an object with its property MyDate sets to DateTime.MinValue, a NULL value is inserted in the corresponding column.


Nicolas


-----Message d'origine-----
De : Andrea Tassinari [mailto:andreaml@i-mconsulting.com] 
Envoyé : vendredi 28 septembre 2007 17:12
À : user-cs@ibatis.apache.org
Objet : Re: nullValue in ResultMap simply does not work

At 15.30 28/09/2007, Bob Hanson wrote:

>.NET 2.0 Nullable types will work correctly with null values.

yes I can understand, but I don't like the idea to convert all DateTime and Guid in nullable DateTime with obviuos consequences on my code. 

Anyway the iBatis manual states that the attribute "nullValue" in the resultmap should work just fine as the inline semantics, I dont understand if I'm experiencing a bug or I am missing something.

Andrea


>On 9/28/07, Andrea Tassinari <<m...@i-mconsulting.com>andreaml@i-mconsulting.com > wrote:
>Hello,
>
>I'm wondering why nullValue attribute does not work at all to me. Consider the following snippets 
>
><!-- sqlMap -->
><resultMaps>
>   <resultMap id="IssueResultMap" class="Issue">
>      <result property="Id"
>               column="Id"
>               type="Guid" 
>               dbType="UniqueIdentifier" />
>       <result property="IssueDate"
>               column="IssueDate"
>               type="DateTime"
>               dbType="DateTime" 
>               nullValue="1/1/0001 12:00:00 AM" />
>   </resultMap >
></resultMaps>
>
><!-- this does **not** work, sqlclient complains about IssueDate-->
><insert id="Insert" parameterClass="Issue"> 
>   INSERT
>     INTO ISSUES
>          (Id, IssueDate)
>     VALUES
>          (#Id#,#IssueDate#)
></insert>
>
><!-- this **does** work -->
><insert id="InsertIssue" parameterClass="Issue"> 
>   INSERT
>     INTO ISSUES
>          (Id, IssueDate)
>     VALUES
>          (#Id#,#IssueDate:DateTime:1/1/0001 12:00:00 AM#)
></insert>
>
>//CS snippet
>Issue issue = new Issue();
>
>//this is only for clarity sake, actually performed by the contructors. 
>issue.IssueDate = new DateTime();
>
>//finally persist to DB
>_mapper.Insert("InsertIssue", issue);
>
>Is there a reason for that? I am wrong or else? It *is* very boring and error-prone to write all nullValue condition in the inline form (consider that I have over 200 insert/update statements in my app. 
>
>My system:
>
>.NET 2.0
>iBatis DataMapper 1.6.1 GA binary version
>Sql Server 2.0
>using provider sqlServer2.0 as shipped in providers.config
>
>Thanks for any support.
>
>--
>Kind Regards
>Andrea 
>
>
>
>
>No virus found in this incoming message.
>Checked by AVG Free Edition. 
>Version: 7.5.488 / Virus Database: 269.13.33/1034 - Release Date: 27/09/2007 17.00


Re: RE : RE : nullValue in ResultMap simply does not work

Posted by AndreaT <an...@i-mconsulting.com>.
On Ven, 28 Settembre 2007 6:31 pm, EXT / ASTEK MOUSSON Nicolas disse:

> Your result-map is not helpful for your Insert scenario. Result maps only
> serves for SELECT statements.
>
>
> Nicolas

I think you are right, I got confused between resultMaps and
parameterMaps. I should build a parametemap and use it in the
insert/update statement

<insert id="" paramaterMap="">

instead of

<insert id="" paramaterClass="">


-- 
AndreaT


RE : RE : nullValue in ResultMap simply does not work

Posted by EXT / ASTEK MOUSSON Nicolas <ex...@sncf.fr>.
<insert id="Insert" parameterClass="Issue">
   INSERT
     INTO ISSUES
          (Id, IssueDate)
     VALUES
          (#Id#,#IssueDate#)
</insert>

 I think this does not work (if you have IssueDate set to DateTime.MinValue for example), because it tries to insert a date (01/01/0001) that is outside of the acceptable values for the datetime type of your database.

Your second statement works, because it inserts a NULL value for the date:

<insert id="InsertIssue" parameterClass="Issue">
   INSERT
     INTO ISSUES
          (Id, IssueDate)
     VALUES
          (#Id#,#IssueDate:DateTime:1/1/0001 12:00:00 AM#)
</insert>

Your result-map is not helpful for your Insert scenario. Result maps only serves for SELECT statements.


Nicolas

-----Message d'origine-----
De : AndreaT [mailto:andreaml@i-mconsulting.com] 
Envoyé : vendredi 28 septembre 2007 17:44
À : user-cs@ibatis.apache.org
Objet : Re: RE : nullValue in ResultMap simply does not work


>
> I think you miss something, because all works fine with the inline syntax
> for null values...
>
> Example of SQL Insert :
>
> 		INSERT INTO TABLEXXX
>             (
> 	          Column1,
>                 Column2
>             )
>             VALUES
>             (
>                 #Id#,
>                 #MyDate:DateTime:01/01/0001 00:00:00#
>             )
>
> 	Then if you pass an object with its property MyDate sets to
> DateTime.MinValue, a NULL value is inserted in the corresponding column.
>

That's the point, Nicolas, the inline syntax works (even for me), the
*equivalent* resultMap syntax does *not*. The question is: why.

Andrea


> Nicolas
>
>
> -----Message d'origine-----
> De : Andrea Tassinari [mailto:andreaml@i-mconsulting.com]
> Envoyé : vendredi 28 septembre 2007 17:12
> À : user-cs@ibatis.apache.org
> Objet : Re: nullValue in ResultMap simply does not work
>
> At 15.30 28/09/2007, Bob Hanson wrote:
>
>>.NET 2.0 Nullable types will work correctly with null values.
>
> yes I can understand, but I don't like the idea to convert all DateTime
> and Guid in nullable DateTime with obviuos consequences on my code.
>
> Anyway the iBatis manual states that the attribute "nullValue" in the
> resultmap should work just fine as the inline semantics, I dont understand
> if I'm experiencing a bug or I am missing something.
>
> Andrea
>
>
>>On 9/28/07, Andrea Tassinari
>> <<m...@i-mconsulting.com>andreaml@i-mconsulting.com > wrote:
>>Hello,
>>
>>I'm wondering why nullValue attribute does not work at all to me.
>> Consider the following snippets
>>
>><!-- sqlMap -->
>><resultMaps>
>>   <resultMap id="IssueResultMap" class="Issue">
>>      <result property="Id"
>>               column="Id"
>>               type="Guid"
>>               dbType="UniqueIdentifier" />
>>       <result property="IssueDate"
>>               column="IssueDate"
>>               type="DateTime"
>>               dbType="DateTime"
>>               nullValue="1/1/0001 12:00:00 AM" />
>>   </resultMap >
>></resultMaps>
>>
>><!-- this does **not** work, sqlclient complains about IssueDate-->
>><insert id="Insert" parameterClass="Issue">
>>   INSERT
>>     INTO ISSUES
>>          (Id, IssueDate)
>>     VALUES
>>          (#Id#,#IssueDate#)
>></insert>
>>
>><!-- this **does** work -->
>><insert id="InsertIssue" parameterClass="Issue">
>>   INSERT
>>     INTO ISSUES
>>          (Id, IssueDate)
>>     VALUES
>>          (#Id#,#IssueDate:DateTime:1/1/0001 12:00:00 AM#)
>></insert>
>>
>>//CS snippet
>>Issue issue = new Issue();
>>
>>//this is only for clarity sake, actually performed by the contructors.
>>issue.IssueDate = new DateTime();
>>
>>//finally persist to DB
>>_mapper.Insert("InsertIssue", issue);
>>
>>Is there a reason for that? I am wrong or else? It *is* very boring and
>> error-prone to write all nullValue condition in the inline form (consider
>> that I have over 200 insert/update statements in my app.
>>
>>My system:
>>
>>.NET 2.0
>>iBatis DataMapper 1.6.1 GA binary version
>>Sql Server 2.0
>>using provider sqlServer2.0 as shipped in providers.config
>>
>>Thanks for any support.
>>
>>--
>>Kind Regards
>>Andrea
>>
>>
>>
>>
>>No virus found in this incoming message.
>>Checked by AVG Free Edition.
>>Version: 7.5.488 / Virus Database: 269.13.33/1034 - Release Date:
>> 27/09/2007 17.00
>
>


-- 
AndreaT


Re: RE : nullValue in ResultMap simply does not work

Posted by AndreaT <an...@i-mconsulting.com>.
>
> I think you miss something, because all works fine with the inline syntax
> for null values...
>
> Example of SQL Insert :
>
> 		INSERT INTO TABLEXXX
>             (
> 	          Column1,
>                 Column2
>             )
>             VALUES
>             (
>                 #Id#,
>                 #MyDate:DateTime:01/01/0001 00:00:00#
>             )
>
> 	Then if you pass an object with its property MyDate sets to
> DateTime.MinValue, a NULL value is inserted in the corresponding column.
>

That's the point, Nicolas, the inline syntax works (even for me), the
*equivalent* resultMap syntax does *not*. The question is: why.

Andrea


> Nicolas
>
>
> -----Message d'origine-----
> De : Andrea Tassinari [mailto:andreaml@i-mconsulting.com]
> Envoyé : vendredi 28 septembre 2007 17:12
> À : user-cs@ibatis.apache.org
> Objet : Re: nullValue in ResultMap simply does not work
>
> At 15.30 28/09/2007, Bob Hanson wrote:
>
>>.NET 2.0 Nullable types will work correctly with null values.
>
> yes I can understand, but I don't like the idea to convert all DateTime
> and Guid in nullable DateTime with obviuos consequences on my code.
>
> Anyway the iBatis manual states that the attribute "nullValue" in the
> resultmap should work just fine as the inline semantics, I dont understand
> if I'm experiencing a bug or I am missing something.
>
> Andrea
>
>
>>On 9/28/07, Andrea Tassinari
>> <<m...@i-mconsulting.com>andreaml@i-mconsulting.com > wrote:
>>Hello,
>>
>>I'm wondering why nullValue attribute does not work at all to me.
>> Consider the following snippets
>>
>><!-- sqlMap -->
>><resultMaps>
>>   <resultMap id="IssueResultMap" class="Issue">
>>      <result property="Id"
>>               column="Id"
>>               type="Guid"
>>               dbType="UniqueIdentifier" />
>>       <result property="IssueDate"
>>               column="IssueDate"
>>               type="DateTime"
>>               dbType="DateTime"
>>               nullValue="1/1/0001 12:00:00 AM" />
>>   </resultMap >
>></resultMaps>
>>
>><!-- this does **not** work, sqlclient complains about IssueDate-->
>><insert id="Insert" parameterClass="Issue">
>>   INSERT
>>     INTO ISSUES
>>          (Id, IssueDate)
>>     VALUES
>>          (#Id#,#IssueDate#)
>></insert>
>>
>><!-- this **does** work -->
>><insert id="InsertIssue" parameterClass="Issue">
>>   INSERT
>>     INTO ISSUES
>>          (Id, IssueDate)
>>     VALUES
>>          (#Id#,#IssueDate:DateTime:1/1/0001 12:00:00 AM#)
>></insert>
>>
>>//CS snippet
>>Issue issue = new Issue();
>>
>>//this is only for clarity sake, actually performed by the contructors.
>>issue.IssueDate = new DateTime();
>>
>>//finally persist to DB
>>_mapper.Insert("InsertIssue", issue);
>>
>>Is there a reason for that? I am wrong or else? It *is* very boring and
>> error-prone to write all nullValue condition in the inline form (consider
>> that I have over 200 insert/update statements in my app.
>>
>>My system:
>>
>>.NET 2.0
>>iBatis DataMapper 1.6.1 GA binary version
>>Sql Server 2.0
>>using provider sqlServer2.0 as shipped in providers.config
>>
>>Thanks for any support.
>>
>>--
>>Kind Regards
>>Andrea
>>
>>
>>
>>
>>No virus found in this incoming message.
>>Checked by AVG Free Edition.
>>Version: 7.5.488 / Virus Database: 269.13.33/1034 - Release Date:
>> 27/09/2007 17.00
>
>


-- 
AndreaT