简体   繁体   中英

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"
jdbcType="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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM