ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Todorovich, Milo" <Milo_Todorov...@pamperedchef.com>
Subject RE: howto : Degenerated case of heterogenous lists.
Date Wed, 14 Feb 2007 16:22:39 GMT
You could also create one SQL statement like this:
    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 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 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 id="AddressResult3" class="Address">
    <result column="address_line1_3" property="addressLine1"/> 
    <result column="address_line1_3" property="addressLine2"/> 
    <result column="city_3" property="city"/>
Good luck,

From: Brandon Goodin [mailto:brandon.goodin@gmail.com] 
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
	getAddress1() {
	  if (addresses.getSize() > 0) return addresses.get(0) : return
	getAddress2() {
	  if (addresses.getSize() > 1) return addresses.get(1) : return
	getAddress3() {
	  if (addresses.getSize() > 2) return addresses.get(2) : return
	On 2/14/07, Thibaut Fagart <thibaut.fagart@hsbc.fr> wrote: 

		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,
		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:
		Sent from the iBATIS - User - Java mailing list archive
at Nabble.com.

View raw message