Hi Ka-Wai,

I find the easiest way to do that kind of mapping is in the domain object, itself.

public class Customer {
   SubObject _subObject = SubObject.Empty;

   public SubObject MySubObject {
      get { return _subObject; }
      set {
         if (null == value)
            _subObject = SubObject.Empty;
         else
            _subObject = value;
      }
   }
}

It also protects you from accidentally setting the property null, somewhere else in your code.

Cheers,

Peter

Ka-Wai Chan wrote:
Hello
I have a 1 to 0 or 1 relationship mapped as follow <result property="SubObject" column="sub_object_id" select="SelectBySubtObjectId"/> This works fine, but what we are trying to implement is the NullObject pattern in which a null value is mapped to a specific null object instead of null. ie. In Parent object, I have a reference called SubObject. Ibatis right now will set that reference to null when a database value of null is encountered, what I want is for Ibatis to set that value to SubObject.NULL instead. Is this possible? What is the proper way of doing this? I have tried implementing ITypeHandlerCallback by doing the following but doesn't work. When is the NullValue getter called? public void SetParameter(IParameterSetter setter, object parameter)
        {
        }
public object GetResult(IResultGetter getter)
        {
            return getter.Value;
        }
public object ValueOf(string s)
        {
            return s;
        }
public object NullValue
        {
            get { return SubObject.NULL; }
        }
Thanks,
Ka-Wai

Reply via email to