ibatis-user-cs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "袁海鹏" <yuanhaip...@gmail.com>
Subject Help! Map one column to an object!
Date Mon, 03 Sep 2007 14:35:36 GMT
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

Mime
View raw message