You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Prateek Asthana <hk...@gmail.com> on 2008/05/25 02:51:35 UTC

Complex Collections - More than one foreign key

Hi,
Below snippet helps us retrieve data from two tables linked by a
single foreign key.

<resultMap id="ResultOrderInfoMap"
class="org.apache.mapper2.examples.bean.OrderInfo">
	<result property="order.orderId" column="orderId" />
	<result property="orderItemList" column="orderId"
select="Ch6.getOrderItemList" />
</resultMap>


<resultMap id="ResultOrderItemMap"
class="org.apache.mapper2.examples.bean.OrderItem">
	<result property="orderId" column="orderId" />
	<result property="orderItemId" column="orderItemId" />
</resultMap>


<select id="getOrderInfoList" resultMap="ResultOrderInfoMap">
	select orderId from orders where accountId = #value#
</select>


<select id="getOrderItemList" resultMap="ResultOrderItemMap">
	select orderId, orderItemId from orderItem
	where orderid = #value#
</select>


In above case, records from both table are retrieved using
orderItem.orderId=orders.orderId; This case has only has one foreign
key constrant;

If the scenario involved two columns as foreign key constraints i.e
orderItem.orderId=orders.orderId AND orderItem.origin=orders.origin
then how could we specify that ?

Thanks
Prateek

Re: Complex Collections - More than one foreign key

Posted by Prateek Asthana <hk...@gmail.com>.
Clinton,
Would we be specify using javaType as shown below:

<result property="orderList"
select="Ch6.getOrderInfoList"
column="accountId"
javaType=Vector/>

Thanks
Prateek



On Sat, May 24, 2008 at 10:34 PM, Clinton Begin <cl...@gmail.com> wrote:
> It will use ArrayList if you specify a List class.  Otherwise, if you
> specify the concrete implementation, I'm pretty sure that should work
> too, as long as it implements the List interface..
>
> On Sat, May 24, 2008 at 7:50 PM, Prateek Asthana <hk...@gmail.com> wrote:
>> Clinton,
>> Thanks for your reply. I have one more question pertaining to the
>> implementation details. As we see for the below example one Order can
>> have multiple Order Items. Talking in terms of Java, how does the
>> order Order class store the collection of OrderItem objects. Can it
>> use any implementation of java.util.Collection (i.e Vector or List or
>> Array and so on).
>>
>> Thanks,
>> Prateek
>>
>>
>> On Sat, May 24, 2008 at 9:27 PM, Clinton Begin <cl...@gmail.com> wrote:
>>> In the result you'd put something like this in the column attribute:
>>>
>>> <result property="orderItemList"
>>> column="{param1=orders.orderId,param2=orders.origin}"
>>> select="Ch6.getOrderItemList" />
>>>
>>> Then in the SQL, you'd put something like this:
>>>
>>> ...orderItem.orderId=#param1# AND orderItem.origin=#param2#...
>>>
>>> Cheers,
>>> Clinton
>>>
>>> On Sat, May 24, 2008 at 6:51 PM, Prateek Asthana <hk...@gmail.com> wrote:
>>>> Hi,
>>>> Below snippet helps us retrieve data from two tables linked by a
>>>> single foreign key.
>>>>
>>>> <resultMap id="ResultOrderInfoMap"
>>>> class="org.apache.mapper2.examples.bean.OrderInfo">
>>>>        <result property="order.orderId" column="orderId" />
>>>>        <result property="orderItemList" column="orderId"
>>>> select="Ch6.getOrderItemList" />
>>>> </resultMap>
>>>>
>>>>
>>>> <resultMap id="ResultOrderItemMap"
>>>> class="org.apache.mapper2.examples.bean.OrderItem">
>>>>        <result property="orderId" column="orderId" />
>>>>        <result property="orderItemId" column="orderItemId" />
>>>> </resultMap>
>>>>
>>>>
>>>> <select id="getOrderInfoList" resultMap="ResultOrderInfoMap">
>>>>        select orderId from orders where accountId = #value#
>>>> </select>
>>>>
>>>>
>>>> <select id="getOrderItemList" resultMap="ResultOrderItemMap">
>>>>        select orderId, orderItemId from orderItem
>>>>        where orderid = #value#
>>>> </select>
>>>>
>>>>
>>>> In above case, records from both table are retrieved using
>>>> orderItem.orderId=orders.orderId; This case has only has one foreign
>>>> key constrant;
>>>>
>>>> If the scenario involved two columns as foreign key constraints i.e
>>>> orderItem.orderId=orders.orderId AND orderItem.origin=orders.origin
>>>> then how could we specify that ?
>>>>
>>>> Thanks
>>>> Prateek
>>>>
>>>
>>
>

Re: Complex Collections - More than one foreign key

Posted by Clinton Begin <cl...@gmail.com>.
It will use ArrayList if you specify a List class.  Otherwise, if you
specify the concrete implementation, I'm pretty sure that should work
too, as long as it implements the List interface..

On Sat, May 24, 2008 at 7:50 PM, Prateek Asthana <hk...@gmail.com> wrote:
> Clinton,
> Thanks for your reply. I have one more question pertaining to the
> implementation details. As we see for the below example one Order can
> have multiple Order Items. Talking in terms of Java, how does the
> order Order class store the collection of OrderItem objects. Can it
> use any implementation of java.util.Collection (i.e Vector or List or
> Array and so on).
>
> Thanks,
> Prateek
>
>
> On Sat, May 24, 2008 at 9:27 PM, Clinton Begin <cl...@gmail.com> wrote:
>> In the result you'd put something like this in the column attribute:
>>
>> <result property="orderItemList"
>> column="{param1=orders.orderId,param2=orders.origin}"
>> select="Ch6.getOrderItemList" />
>>
>> Then in the SQL, you'd put something like this:
>>
>> ...orderItem.orderId=#param1# AND orderItem.origin=#param2#...
>>
>> Cheers,
>> Clinton
>>
>> On Sat, May 24, 2008 at 6:51 PM, Prateek Asthana <hk...@gmail.com> wrote:
>>> Hi,
>>> Below snippet helps us retrieve data from two tables linked by a
>>> single foreign key.
>>>
>>> <resultMap id="ResultOrderInfoMap"
>>> class="org.apache.mapper2.examples.bean.OrderInfo">
>>>        <result property="order.orderId" column="orderId" />
>>>        <result property="orderItemList" column="orderId"
>>> select="Ch6.getOrderItemList" />
>>> </resultMap>
>>>
>>>
>>> <resultMap id="ResultOrderItemMap"
>>> class="org.apache.mapper2.examples.bean.OrderItem">
>>>        <result property="orderId" column="orderId" />
>>>        <result property="orderItemId" column="orderItemId" />
>>> </resultMap>
>>>
>>>
>>> <select id="getOrderInfoList" resultMap="ResultOrderInfoMap">
>>>        select orderId from orders where accountId = #value#
>>> </select>
>>>
>>>
>>> <select id="getOrderItemList" resultMap="ResultOrderItemMap">
>>>        select orderId, orderItemId from orderItem
>>>        where orderid = #value#
>>> </select>
>>>
>>>
>>> In above case, records from both table are retrieved using
>>> orderItem.orderId=orders.orderId; This case has only has one foreign
>>> key constrant;
>>>
>>> If the scenario involved two columns as foreign key constraints i.e
>>> orderItem.orderId=orders.orderId AND orderItem.origin=orders.origin
>>> then how could we specify that ?
>>>
>>> Thanks
>>> Prateek
>>>
>>
>

Re: Complex Collections - More than one foreign key

Posted by Prateek Asthana <hk...@gmail.com>.
Clinton,
Thanks for your reply. I have one more question pertaining to the
implementation details. As we see for the below example one Order can
have multiple Order Items. Talking in terms of Java, how does the
order Order class store the collection of OrderItem objects. Can it
use any implementation of java.util.Collection (i.e Vector or List or
Array and so on).

Thanks,
Prateek


On Sat, May 24, 2008 at 9:27 PM, Clinton Begin <cl...@gmail.com> wrote:
> In the result you'd put something like this in the column attribute:
>
> <result property="orderItemList"
> column="{param1=orders.orderId,param2=orders.origin}"
> select="Ch6.getOrderItemList" />
>
> Then in the SQL, you'd put something like this:
>
> ...orderItem.orderId=#param1# AND orderItem.origin=#param2#...
>
> Cheers,
> Clinton
>
> On Sat, May 24, 2008 at 6:51 PM, Prateek Asthana <hk...@gmail.com> wrote:
>> Hi,
>> Below snippet helps us retrieve data from two tables linked by a
>> single foreign key.
>>
>> <resultMap id="ResultOrderInfoMap"
>> class="org.apache.mapper2.examples.bean.OrderInfo">
>>        <result property="order.orderId" column="orderId" />
>>        <result property="orderItemList" column="orderId"
>> select="Ch6.getOrderItemList" />
>> </resultMap>
>>
>>
>> <resultMap id="ResultOrderItemMap"
>> class="org.apache.mapper2.examples.bean.OrderItem">
>>        <result property="orderId" column="orderId" />
>>        <result property="orderItemId" column="orderItemId" />
>> </resultMap>
>>
>>
>> <select id="getOrderInfoList" resultMap="ResultOrderInfoMap">
>>        select orderId from orders where accountId = #value#
>> </select>
>>
>>
>> <select id="getOrderItemList" resultMap="ResultOrderItemMap">
>>        select orderId, orderItemId from orderItem
>>        where orderid = #value#
>> </select>
>>
>>
>> In above case, records from both table are retrieved using
>> orderItem.orderId=orders.orderId; This case has only has one foreign
>> key constrant;
>>
>> If the scenario involved two columns as foreign key constraints i.e
>> orderItem.orderId=orders.orderId AND orderItem.origin=orders.origin
>> then how could we specify that ?
>>
>> Thanks
>> Prateek
>>
>

Re: Complex Collections - More than one foreign key

Posted by Clinton Begin <cl...@gmail.com>.
In the result you'd put something like this in the column attribute:

<result property="orderItemList"
column="{param1=orders.orderId,param2=orders.origin}"
select="Ch6.getOrderItemList" />

Then in the SQL, you'd put something like this:

...orderItem.orderId=#param1# AND orderItem.origin=#param2#...

Cheers,
Clinton

On Sat, May 24, 2008 at 6:51 PM, Prateek Asthana <hk...@gmail.com> wrote:
> Hi,
> Below snippet helps us retrieve data from two tables linked by a
> single foreign key.
>
> <resultMap id="ResultOrderInfoMap"
> class="org.apache.mapper2.examples.bean.OrderInfo">
>        <result property="order.orderId" column="orderId" />
>        <result property="orderItemList" column="orderId"
> select="Ch6.getOrderItemList" />
> </resultMap>
>
>
> <resultMap id="ResultOrderItemMap"
> class="org.apache.mapper2.examples.bean.OrderItem">
>        <result property="orderId" column="orderId" />
>        <result property="orderItemId" column="orderItemId" />
> </resultMap>
>
>
> <select id="getOrderInfoList" resultMap="ResultOrderInfoMap">
>        select orderId from orders where accountId = #value#
> </select>
>
>
> <select id="getOrderItemList" resultMap="ResultOrderItemMap">
>        select orderId, orderItemId from orderItem
>        where orderid = #value#
> </select>
>
>
> In above case, records from both table are retrieved using
> orderItem.orderId=orders.orderId; This case has only has one foreign
> key constrant;
>
> If the scenario involved two columns as foreign key constraints i.e
> orderItem.orderId=orders.orderId AND orderItem.origin=orders.origin
> then how could we specify that ?
>
> Thanks
> Prateek
>