iBatis 插入非空字段的问题

最近才开始研究iBatis,无意中发现用iBatis向数据库表中插入数据的时候,有时候出现问题:
比如下面的情况

数据库表 A
字段:id int 自增
字段:name varchar 非空 默认 " "
字段:pwd varchar 非空 默认 "1"

实体类A 字段 id,name,pwd getter() setter() ...不加赘述

sqlMap.xml 中的insert语句

<![CDATA[
insert into A (name,pwd)
values(#name#,#pwd# )
]]>

select last_insert_id();

执行insert方法
A a=new A();
a.setName("test");

未给pwd赋值的情况下,总是报如下错误:

[color=red]Exception in thread "main" org.springframework.dao.DataIntegrityViolationException: SqlMapClient operation; SQL [];

--- The error occurred in bo/A.xml.

--- The error occurred while applying a parameter map.

--- Check the A.insertSql-InlineParameterMap.

--- Check the statement (update failed).

--- Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'pwd' cannot be null; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:

--- The error occurred in bo/A.xml.

--- The error occurred while applying a parameter map.

--- Check the A.insertSql-InlineParameterMap.

--- Check the statement (update failed). [/color]

但是给pwd赋值的情况下,就正常执行,现在就有此疑问:
pwd在数据库中已经有默认值,为什么我插入之前还得必须赋值?

在现实中表中字段决不会如此少,请问有没有更好的配置方法,

可以在未赋值的情况下,向数据表中插入数据,非空字段为默认值???、

改实体类中的getter方法就免了,最好是如何配置 .xml

忘了加isEmpty了,抱歉
insert into A (name,pwd) values(#name#,#pwd# )
改成这样啦
insert into A (name,pwd) values(#name#,

#pwd#


null

)

你的这个增加语句:insert into A (name,pwd) values(#name#,#pwd# ) 表示要给两个字段增加值。

改成这样:insert into A (name) values(#name# )

你不用pwd也可以增加成功的。

但最好在程序里控制默认值。比如pwd如果给null值,就使用默认值进行增加。

insert into A (name,pwd) values(#name#,#pwd# )
改成这样啦
insert into A (name,pwd) values(#name#,

#pwd#

)

就行了,我项目也是这样用的