开发者

how to cope with a null Date in an ibatis mapping

I have the following in one of my result mappings.

<result property="updateDate" column="update_date" javaType="java.util.Date"
jdb开发者_如何学JAVAcType="DATE" nullValue="01/01/1900"/>

basically updateDate is a setter that accepts Date. However, sometimes updateDate will be null in the database. In those cases I want to have a default date of 01/01/1900.

However, the above mappings gives me the following error when updateDate is null from DB

Cause: java.lang.RuntimeException: Error setting property 'setUpdateDate'


Is the problem that your nullValue="01/01/1900" is trying to pass a string into updateDate setter? If you took that out, I assume the setter would be called by iBatis with 'null' and then you could apply the default in your setter in the Java code.


Can you change your updateDate method to take a null and set the "01/01/1900" Date in there?

This message can also occur when the setter doesn't exist or is spelled incorrectly too, make sure that's not the case.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜