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 Guy Rouillier <gu...@burntmail.com> on 2009/10/21 07:47:18 UTC

Not identifying missing parameter names

I'm using the new multiple parameter capability in the latest version 3 
beta.  I have a method like this in my mapper Java class:

List<Contact> selectContactType(@Param("aCustId") String aCustId, 
@Param("eContactType") Contact.ContactTypeEnum eContactType);


These parameters are used in the WHERE clause.  Here is the text from 
the XML file:

where
    cust_id = #{aCustId, javaType=String, jdbcType=VARCHAR}
    and contact_tp_id = #{eContactType.intValue, javaType=int, 
jdbcType=VARCHAR}

When I first created this, I had a typo in the XML:

   cust_id = #{cust_id}

My application simply reported no data; no errors were logged anywhere.

Since I'm using named parameters in a Java map, shouldn't iBatis be able 
to tell that the #{cust_id} value I had specified in the SQL was not in 
the map?  It then could have logged an error, which would have greatly 
assisted in identifying why my app wasn't showing any data.

Thanks.

-- 
Guy Rouillier

---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: Not identifying missing parameter names

Posted by Guy Rouillier <gu...@burntmail.com>.
Nathan Maves wrote:
> I dont think that this is possible from this direction.  Remember that 
> the sqlmap was just doing a map.get("cust_id") and getting null back 
> which is the expected behavior.

An easy solution would be to first check if the map entry exists:

if (map.containsKey(keyVal))
    param = map.get(keyVal);
else
    throw new Exception("Query contains param: " + param.getName() + 
"that was not found in map");

> 
> On the flip side you might be able to have a check on the @Param to see 
> if there is actually a var in the sqlmap named that.  We dont do that 
> right now but you could extend IB to do that if you wanted to.
> 
> I think we have the best solution right now for most situations.
> One way to get around this would be to use an actual class for your 
> parameter.  This way you will get this check by default.  And you can be 
> a bit more type safe.

Thanks for the reply.  Adding the above is trivial and provides valuable 
feedback to the developer for otherwise tricky to locate problems.

> 
> Nathan
> 
> On Tue, Oct 20, 2009 at 11:47 PM, Guy Rouillier <guyr-ml1@burntmail.com 
> <ma...@burntmail.com>> wrote:
> 
>     I'm using the new multiple parameter capability in the latest
>     version 3 beta.  I have a method like this in my mapper Java class:
> 
>     List<Contact> selectContactType(@Param("aCustId") String aCustId,
>     @Param("eContactType") Contact.ContactTypeEnum eContactType);
> 
> 
>     These parameters are used in the WHERE clause.  Here is the text
>     from the XML file:
> 
>     where
>       cust_id = #{aCustId, javaType=String, jdbcType=VARCHAR}
>       and contact_tp_id = #{eContactType.intValue, javaType=int,
>     jdbcType=VARCHAR}
> 
>     When I first created this, I had a typo in the XML:
> 
>      cust_id = #{cust_id}
> 
>     My application simply reported no data; no errors were logged anywhere.
> 
>     Since I'm using named parameters in a Java map, shouldn't iBatis be
>     able to tell that the #{cust_id} value I had specified in the SQL
>     was not in the map?  It then could have logged an error, which would
>     have greatly assisted in identifying why my app wasn't showing any data.
> 
>     Thanks.
> 
>     -- 
>     Guy Rouillier
> 
>     ---------------------------------------------------------------------
>     To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
>     <ma...@ibatis.apache.org>
>     For additional commands, e-mail: user-java-help@ibatis.apache.org
>     <ma...@ibatis.apache.org>
> 
> 


-- 
Guy Rouillier

---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: Not identifying missing parameter names

Posted by Nathan Maves <na...@gmail.com>.
I dont think that this is possible from this direction.  Remember that the
sqlmap was just doing a map.get("cust_id") and getting null back which is
the expected behavior.
On the flip side you might be able to have a check on the @Param to see if
there is actually a var in the sqlmap named that.  We dont do that right now
but you could extend IB to do that if you wanted to.

I think we have the best solution right now for most situations.
One way to get around this would be to use an actual class for your
parameter.  This way you will get this check by default.  And you can be a
bit more type safe.

Nathan

On Tue, Oct 20, 2009 at 11:47 PM, Guy Rouillier <gu...@burntmail.com>wrote:

> I'm using the new multiple parameter capability in the latest version 3
> beta.  I have a method like this in my mapper Java class:
>
> List<Contact> selectContactType(@Param("aCustId") String aCustId,
> @Param("eContactType") Contact.ContactTypeEnum eContactType);
>
>
> These parameters are used in the WHERE clause.  Here is the text from the
> XML file:
>
> where
>   cust_id = #{aCustId, javaType=String, jdbcType=VARCHAR}
>   and contact_tp_id = #{eContactType.intValue, javaType=int,
> jdbcType=VARCHAR}
>
> When I first created this, I had a typo in the XML:
>
>  cust_id = #{cust_id}
>
> My application simply reported no data; no errors were logged anywhere.
>
> Since I'm using named parameters in a Java map, shouldn't iBatis be able to
> tell that the #{cust_id} value I had specified in the SQL was not in the
> map?  It then could have logged an error, which would have greatly assisted
> in identifying why my app wasn't showing any data.
>
> Thanks.
>
> --
> Guy Rouillier
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org
>
>