ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Larry Meadors <larry.mead...@gmail.com>
Subject Re: A question about nullValue in resultMap.
Date Fri, 28 Jan 2005 20:19:52 GMT
Just curious: If you can have null values, why are you using primitive
values. You do realize that even if we do not call the setter, the
property holder will be set to 0 anyway, right?

public class MyBean{
  int myProp; // <-- since this MUST be initialized, the JVM sets it to 0
  public int getMyProp(){
    return myProp;
  public void setMyProp(int val){
    myProp = val;
  public static void main(String[] a){
    MyBean myBean = new MyBean();
    System.out.println(myBean.getMyProp()); // <-- will be 0

So, do you have some other logig in your setter or something that
detects if it was called, or is there some other compelling reason for
this? IMO, it seems silly.


On Fri, 28 Jan 2005 15:10:19 -0500, Bing Zou <xiguamaillist@gmail.com> wrote:
> Hi,
> So far in iBbatis, when the parameter of the result Bean's setter is
> primitive type (for example, setParentCategoryID(long id)),  if the
> corresponding column might get a database NULL value during execution,
> we have at least three solutions:
> 1. Change the Bean's setter to use Object type parameter instead of
> primitive type. (for example, use setParentCategoryID(Long id_object)
> instead).
> 2. Use ResultMap and specify nullValue of the nullable property.
> 3. Use ResultMap and specify TypeHandler to take care of the returned
> Null value.
> Obviously solution 1 is not a good one while solution 2 and 3 require
> using ResultMap instead of using ResultClass directly.
> Now the question is, I want to keep the sqlmap xml file as simple as
> possible, so I want to use as much implicit result mapping as
> possible. (Because using resultMap will make the xml file a little bit
> harder to read, understand, debug and maintain.) I want to avoid
> ResultMap even there is nullable column in the SQL statement. So I
> hope iBatis could take care of the null values for me.
> I am wondering whether the iBatis team will consider adding one more
> property to the iBatis configuration file like SkipSettingNullResult.
> If SkipSettingNullResult=true, while iBatis sees a Null value returned
> from the resultSet, if the corresponding setter is taking a primitive
> type parameter, iBatis simply skip this setter and the Bean will use
> the default value instead of executing the setter.
> I will sincerely appreciate it if the iBatis team could make it happen
> in the near future.
> Thanks a lot.
> Bing

View raw message