You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-cs@ibatis.apache.org by 袁海鹏 <yu...@gmail.com> on 2007/09/03 16:35:36 UTC

Help! Map one column to an object!

Hi all,
   I was blocked by one problem, how can I get an iBatis solution to fix it?

   Class Person have many properties such as weight,height,hairColor and so
on.
   I wanna create a hashTable property to hold all the other properties, but
I was failed.
   Any good suggestions will be appreciated!

   public class Person
    {
        public int ID {}
        public string Name{}
        public HashTable Properties;

        //other methods
    }

    public class Property
    {
        public string DataValue{}
        public string DataType{}

        //other properties and methods
    }

   <resultMap id = "ResultWeightProperty" class = "Property">
        <result property = "DataValue" column = "Weight"/>
        <!--no column-->
        <result property = "DataType" value = "int"/>
   <resultMap>

   <resultMap id = "PersonProperties" class = "HashTable">
        <result property ="weight"  resultMapping = "ResultWeightProperty"/>
        <result property ="height"  resultMapping = "ResultHeightProperty"/>
   </resultMap>

    <resultMap id = "ResultPerson" class = "Person">
       <result property = "ID" column = "id"/>
        <result property = "Name" column = "name"/>
        <result property = "Properties" resultMapping= "PersonProperties"/>
    </resultMap>

    <select id = "GetPersonProperties" parameterClass = "int" resultMap =
"ResultPerson">
         select id,name,weight,height,haircolor,.... from person where
person_id = #value#
    </select>

Best Regards