ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cowwoc <cow...@bbs.darktech.org>
Subject Re: "JDBC requires that the JdbcType must be specified for all nullable parameters"
Date Wed, 07 Apr 2010 04:27:18 GMT
On 07/04/2010 12:09 AM, cowwoc wrote:
> Hi,
>     I am getting an error message:
>     "JDBC requires that the JdbcType must be specified for all 
> nullable parameters [...] The error may involve <mapper name>-Inline". 
> Granted, telling me the mapper name is useful but I believe we can 
> improve this error message in two regards:
> 1. I mistakenly read "nullable parameters" as "nullable columns" and 
> wasted time looking for problems in my database schema. I wonder if 
> others have made a similar mistake...? Is it possible to rephrase this 
> as follows? "Mapper methods cannot accept null arguments without a 
> properly configured JdbcType. Either specify a JdbcType or refrain 
> from passing in null."
> 2. I noticed that when this exception is thrown iBatis has quite a bit 
> more information available to it. Is it possible to add the following 
> information to the error message?
> Prepared statement: "SELECT * FROM animals WHERE name = ? AND age > 
> ?", parameter #2 was null
>     This would enable me to track down exactly which parameter was 
> equal to null.
> Thank you,
> Gili

The error message turned out to be even more misleading than I first 
expected. I had this code:

     @Select("SELECT value FROM seat_properties WHERE seat = #{seat} AND 
key = #{key}")
     String get(short seat, String key);

I wrongly assumed that iBatis would grab the parameter names from the 
method declaration. Instead, it names the parameters #{1}, #{2}, etc. 
When iBatis tried invoking this method, it couldn't find #{seat} so it 
assigned it a null value and failed with the aforementioned error 
message. I had to use the @Param annotation to fix this:

     @Select("SELECT value FROM seat_properties WHERE seat = #{seat} AND 
key = #{key}")
     String get(@Param("seat") short seat, @Param("key") String key);

Shouldn't iBatis fail-fast when the parameter it is looking up ("seat" 
in my case) is missing, as opposed to assigning it a null value? A nice 
error message would be "Could not find parameter #{seat}. The following 
parameters are defined: #{1}, #{2}." I would have caught on fairly 
quickly with that error message.


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

View raw message