ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thibaut Fagart <thibaut.fag...@hsbc.fr>
Subject Re: [JDBC type = ARRAY / Java type = ?] howto : Degenerated case of heterogenous lists.
Date Wed, 14 Feb 2007 16:10:08 GMT

Here is the sqlMap I'm trying 

THe idea was to try to create "virtual" classes Address1, Address2 and
Address3, and having IBatis only set the relevant atttriute for each row,
but it does not seem to work.




> <?xml version="1.0" encoding="UTF-8" ?>
> <!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
> "http://ibatis.apache.org/dtd/sql-map-2.dtd">
> <sqlMap namespace="TestIBatis">
> 	<resultMap id="Customer" class="test.ibatis.Customer" groupBy="id">
> 		<result property="id" column="id"/>
> 		<result property="address1" resultMap="TestIBatis.Address1"/>
> 		<result property="address2" resultMap="TestIBatis.Address2"/>
> 		<result property="address3" resultMap="TestIBatis.Address3"/>
> 	</resultMap>
> 	<resultMap id="Address" class="test.ibatis.Address">
> 		<result property="flag" column="flag"/>
> 		<discriminator column="flag" javaType="string">
> 			<subMap value="Address1" resultMap="TestIBatis.Address1"/>
> 			<subMap value="Address2" resultMap="TestIBatis.Address2"/>
> 			<subMap value="Address3" resultMap="TestIBatis.Address3"/>
> 		</discriminator>
> 	</resultMap>
> 
> 	<resultMap id="Address1" class="test.ibatis.Address" extends="Address">
> 		<result property="rue" column="rue"/>
> 	</resultMap>
> 	<resultMap id="Address2" class="test.ibatis.Address" extends="Address">
> 		<result property="rue" column="rue"/>
> 	</resultMap>
> 	<resultMap id="Address3" class="test.ibatis.Address" extends="Address">
> 		<result property="rue" column="rue"/>
> 	</resultMap>
> 
> 	<select id="getCustomerAndAddresses"
> 			parameterClass="java.lang.Integer"
> 			resultMap="Customer">
> 		SELECT c.id, a.rue, a.flag
> 		FROM customer c LEFT OUTER JOIN address a ON c.id = a.customer_id
> 		WHERE c.id = #value#
> 	</select>
> 
> </sqlMap>
> 

I have added some logging in the customer setAddressX methods and here is
the output I get for the following tables
customer (id)
 1

address (customer_id, tex, flag)
(1,none1,Address1)
(1,none2,Address2)
(1,none3,Address3)

And the logs 


> test.ibatis.Customer;DEBUG;main;2007-02-14 17:01:53,669;setAddress1 null
> test.ibatis.Customer;DEBUG;main;2007-02-14 17:01:53,669;setAddress2 null
> test.ibatis.Customer;DEBUG;main;2007-02-14 17:01:53,679;setAddress3 null
> test.ibatis.Customer;DEBUG;main;2007-02-14 17:01:53,689;setAddress1 none1
> test.ibatis.Customer;DEBUG;main;2007-02-14 17:01:53,699;setAddress2 none1
> test.ibatis.Customer;DEBUG;main;2007-02-14 17:01:53,699;setAddress3 none1
> test.ibatis.Customer;DEBUG;main;2007-02-14 17:01:53,709;setAddress1 none2
> test.ibatis.Customer;DEBUG;main;2007-02-14 17:01:53,709;setAddress2 none2
> test.ibatis.Customer;DEBUG;main;2007-02-14 17:01:53,709;setAddress3 none2
> test.ibatis.Customer;DEBUG;main;2007-02-14 17:01:53,719;setAddress1 none3
> test.ibatis.Customer;DEBUG;main;2007-02-14 17:01:53,719;setAddress2 none3
> test.ibatis.Customer;DEBUG;main;2007-02-14 17:01:53,719;setAddress3 none3
> 
> 


According to the log, it seems all the setters are called for each row ,
although only one discriminator should match?
-- 
View this message in context: http://www.nabble.com/howto-%3A-Degenerated-case-of-heterogenous-lists.-tf3227674.html#a8967984
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Mime
View raw message