You could also create one SQL statement like this:
 
select 
    customer.first_name,
    customer.last_name,
    address1.address_line1 as address_line1_1,
    address1.address_line2 as address_line2_1,
    address1.city as city_1,
    address2.address_line1 as address_line1_2,
    address2.address_line2 as address_line2_2,
    address2.city as city_2,
    address3.address_line1 as address_line1_3,
    address3.address_line2 as address_line2_3,
    address3.city as city_3,
    from customer,
address address1,
address address2,
address address3,
where customer.id <http://customer.id/>  = address1.id_customer
and customer.id <http://customer.id/>  = address2.id_customer
and customer.id <http://customer.id/>  = address3.id_customer
and address1.address_flag='Address1'
and address2.address_flag='Address2'
and address3.address_flag='Address3'

 
You would probably need to define three different reslutMaps for the
address so that your address column names do not conflict.
 
<resultMap id="CustomerResult" class="Customer">
    <result column="first_name" property="firstName"/> 
    <result column="last_name" property="lastName"/>
    <result property="address1" resultMap="AddressResult1"/> 
    <result property="address2" resultMap="AddressResult2"/> 
    <result property="address3" resultMap="AddressResult3"/>
</resultMap>

<resultMap id="AddressResult1" class="Address">
    <result column="address_line1_1" property="addressLine1"/> 
    <result column="address_line1_1" property="addressLine2"/> 
    <result column="city_1" property="city"/>
</resultMap>
 
<resultMap id="AddressResult2" class="Address">
    <result column="address_line1_2" property="addressLine1"/> 
    <result column="address_line1_2" property="addressLine2"/> 
    <result column="city_2" property="city"/>
</resultMap>
 
<resultMap id="AddressResult3" class="Address">
    <result column="address_line1_3" property="addressLine1"/> 
    <result column="address_line1_3" property="addressLine2"/> 
    <result column="city_3" property="city"/>
</resultMap>
 
 
Good luck,
Milo-
 
________________________________

From: Brandon Goodin [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, February 14, 2007 9:35 AM
To: user-java@ibatis.apache.org
Subject: Re: howto : Degenerated case of heterogenous lists.



        It could be solved if you combined address1,2,3 into a list and
used the groupby functionality. 
        
        Customer {
                firstName : string
                lastName : string
                addresses : List
        }
        
        If you want to return the address through address1, 2, 3 getters
you could always add the getters and have them draw from the list
indexes.
        
        getAddress1() {
          if (addresses.getSize() > 0) return addresses.get(0) : return
null;
        }
        
        getAddress2() {
          if (addresses.getSize() > 1) return addresses.get(1) : return
null;
        }
        
        getAddress3() {
          if (addresses.getSize() > 2) return addresses.get(2) : return
null;
        }
        
        
        
        Brandon
        
        
        On 2/14/07, Thibaut Fagart <[EMAIL PROTECTED]> wrote: 


                Hi,
                I'm currently evaluating IBatis for the corporation I
work with, and trying
                to use it to solve a case we have.
                
                We have a model like this
                
                Customer {
                        firstName : string
                        lastName : string 
                        address1 : Address
                        address2 : Address
                        address3 : Address
                }
                where Address is a simple class.
                
                All the addresses happen to be stored in the same table,
with a join to the
                customer table, and a flag indicating which address this
is (address1, 
                address2 or address3).
                
                The request that used to be used to solve this case is
something like that
                
                select [customer columns], [address columns],
address_flag  from customer,
                address
                where customer.id = address.id_customer
                
                This would return 3 rows, with the curstomer information
duplicated, and the
                resultSet consuming code would sort out which address
attributes (address1,
                address2 or address3) has to be set with the current row
depending on 
                address_flag value.
                
                I've seen support for returning heterogenous lists using
the discriminator
                tag, but this doesn't solve my problem, does it ?
                
                Would there be a way to solve this case with only 1
request to the database 
                ?
                --
                View this message in context:
http://www.nabble.com/howto-%3A-Degenerated-case-of-heterogenous-lists.-
tf3227674.html#a8966314 
                Sent from the iBATIS - User - Java mailing list archive
at Nabble.com.
                
                


Reply via email to