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 Gavin McLeod <mi...@gmail.com> on 2009/04/14 01:49:54 UTC

(Unknown)

I have the following:

<insert id="insert" parameterClass="domain.Thing">
   insert into thing (thing_id, animal, mineral, vegetable)
   values (
       #thingId#,
       #animal:BOOLEAN:False#,
       #mineral:BOOLEAN:False#,
       #vegetable:BOOLEAN:False#
   )
</insert>

When iBatis executes the above an exception is thrown:

com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in ibatis/business.xml.
--- The error occurred while applying a parameter map.
--- Check the Business.insert-InlineParameterMap.
--- Check the statement (update failed).
--- Cause: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException:
Column 'animal' cannot be null
       at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeUpdate(MappedStatement.java:107)
       at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.insert(SqlMapExecutorDelegate.java:393)


My understanding here is that if the JavaBean property returns a null
value that it is substituted for the value specified in the
parameterMap. The Exception tends to discount this interpretation.

What am I missing?

Thanks in advance
Gav

Re:

Posted by Nathan Maves <na...@gmail.com>.
can you turn on logging to see what values ibatis is sending to the insert?

On Mon, Apr 13, 2009 at 5:49 PM, Gavin McLeod <mi...@gmail.com>wrote:

> I have the following:
>
> <insert id="insert" parameterClass="domain.Thing">
>   insert into thing (thing_id, animal, mineral, vegetable)
>   values (
>       #thingId#,
>       #animal:BOOLEAN:False#,
>       #mineral:BOOLEAN:False#,
>       #vegetable:BOOLEAN:False#
>   )
> </insert>
>
> When iBatis executes the above an exception is thrown:
>
> com.ibatis.common.jdbc.exception.NestedSQLException:
> --- The error occurred in ibatis/business.xml.
> --- The error occurred while applying a parameter map.
> --- Check the Business.insert-InlineParameterMap.
> --- Check the statement (update failed).
> --- Cause:
> com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException:
> Column 'animal' cannot be null
>       at
> com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeUpdate(MappedStatement.java:107)
>       at
> com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.insert(SqlMapExecutorDelegate.java:393)
>
>
> My understanding here is that if the JavaBean property returns a null
> value that it is substituted for the value specified in the
> parameterMap. The Exception tends to discount this interpretation.
>
> What am I missing?
>
> Thanks in advance
> Gav
>

Re:

Posted by Clinton Begin <cl...@gmail.com>.
Yes, that's exactly right Nathan.  I like to believe the world has changed,
and that if we're in such a situation again today, we can just change the
data type in the app.  :-)

Clinton

On Mon, Apr 13, 2009 at 10:08 PM, Nathan Maves <na...@gmail.com>wrote:

> oh right this "feature" was made for the times when you have a nullable
> column in a DB, and for some strange reason, you only have a non-nullable
> java type like a primitive int.
>
>
>
> On Mon, Apr 13, 2009 at 7:59 PM, Larry Meadors <la...@gmail.com>wrote:
>
>> Null value replacement makes my head hurt.
>>
>> It bit me, because it worked exactly the OPPOSITE of what I expected.
>>
>> When doing a select, if the database value is null, ibatis will use
>> the replacement value for your result.
>>
>> When doing an insert, if the parameter property is the replacement
>> value, it'll put null in the database.
>>
>> So in this case, it's doing nothing.
>>
>> :-/
>>
>> However, IIRC, if you set thing.animal to false, it'll use null in the
>> database instead.
>>
>> Larry
>>
>>
>> PS: Hey, aren't you the captain of "The Love Boat"? Oh, no that was
>> Gavin MacLeod...nevermind. :-P
>>
>
>

Re:

Posted by Nathan Maves <na...@gmail.com>.
oh right this "feature" was made for the times when you have a nullable
column in a DB, and for some strange reason, you only have a non-nullable
java type like a primitive int.


On Mon, Apr 13, 2009 at 7:59 PM, Larry Meadors <la...@gmail.com>wrote:

> Null value replacement makes my head hurt.
>
> It bit me, because it worked exactly the OPPOSITE of what I expected.
>
> When doing a select, if the database value is null, ibatis will use
> the replacement value for your result.
>
> When doing an insert, if the parameter property is the replacement
> value, it'll put null in the database.
>
> So in this case, it's doing nothing.
>
> :-/
>
> However, IIRC, if you set thing.animal to false, it'll use null in the
> database instead.
>
> Larry
>
>
> PS: Hey, aren't you the captain of "The Love Boat"? Oh, no that was
> Gavin MacLeod...nevermind. :-P
>

Re:

Posted by Clinton Begin <cl...@gmail.com>.
I've done one better... iBATIS 3 does not support null value replacement at
all.

Cheers then.  :-)

Clinton

On Mon, Apr 13, 2009 at 8:51 PM, Zoran Avtarovski
<zo...@sparecreative.com>wrote:

>  That’s why I’ve never managed to get it to work. Can I suggest that for
> the next version the logic be reversed on inserts. It’s not a big deal as it
> makes sense to implement this type of logic in the business layer but for
> simple projects it might be beneficial.
>
> Z.
>
>
> Null value replacement makes my head hurt.
>
> It bit me, because it worked exactly the OPPOSITE of what I expected.
>
> When doing a select, if the database value is null, ibatis will use
> the replacement value for your result.
>
> When doing an insert, if the parameter property is the replacement
> value, it'll put null in the database.
>
> So in this case, it's doing nothing.
>
> :-/
>
> However, IIRC, if you set thing.animal to false, it'll use null in the
> database instead.
>
> Larry
>
>
> PS: Hey, aren't you the captain of "The Love Boat"? Oh, no that was
> Gavin MacLeod...nevermind. :-P
>
>
>

Re:

Posted by Zoran Avtarovski <zo...@sparecreative.com>.
That¹s why I¹ve never managed to get it to work. Can I suggest that for the
next version the logic be reversed on inserts. It¹s not a big deal as it
makes sense to implement this type of logic in the business layer but for
simple projects it might be beneficial.

Z.

> 
> Null value replacement makes my head hurt.
> 
> It bit me, because it worked exactly the OPPOSITE of what I expected.
> 
> When doing a select, if the database value is null, ibatis will use
> the replacement value for your result.
> 
> When doing an insert, if the parameter property is the replacement
> value, it'll put null in the database.
> 
> So in this case, it's doing nothing.
> 
> :-/
> 
> However, IIRC, if you set thing.animal to false, it'll use null in the
> database instead.
> 
> Larry
> 
> 
> PS: Hey, aren't you the captain of "The Love Boat"? Oh, no that was
> Gavin MacLeod...nevermind. :-P



Re:

Posted by Larry Meadors <la...@gmail.com>.
Null value replacement makes my head hurt.

It bit me, because it worked exactly the OPPOSITE of what I expected.

When doing a select, if the database value is null, ibatis will use
the replacement value for your result.

When doing an insert, if the parameter property is the replacement
value, it'll put null in the database.

So in this case, it's doing nothing.

:-/

However, IIRC, if you set thing.animal to false, it'll use null in the
database instead.

Larry


PS: Hey, aren't you the captain of "The Love Boat"? Oh, no that was
Gavin MacLeod...nevermind. :-P