ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mike Fagan <mfa...@tde.com>
Subject Re: N+1 with a twist?
Date Thu, 10 Feb 2005 23:07:24 GMT
If you are using oracle the following is legal:

select p.*, c.name child_name, c.description
from parent p, child c
WHERE p.id = c.parent_id;


Nathan Maves wrote:

> That is how I was going to handle them.  I was just looking to see if 
> there was some tricky way  to use "select *" from multiple tables.  I 
> have one table that has 30 columns in it.  It is very painful to list 
> out each column :)
>
> Nathan
> On Feb 10, 2005, at 3:50 PM, Kris A. Jenkins wrote:
>
>> Nathan,
>>
>> Ambiguous column names are easily handled.  Just
>> differentiate the names in the query, then you can
>> assign them explicitly in the resultMaps.  Here's an
>> example with an ambiguous 'name' column:
>>
>> <sqlMap namespace="Example">
>>  <resultMap id="parentResult" class="com.eg.Parent"
>> groupBy="parentId">
>>   <result property="parentId" column="parent_id"/>
>>   <result property="name" column="parent_name"/>
>>   <result property="children"
>> resultMap="Example.childResult"/>
>>  </resultMap>
>>
>>  <resultMap id="childResult" class="com.eg.Child">
>>   <result property="name" column="child_name"/>
>>   <result property="description"
>> column="description"/>
>> column="broadcastEndDate"/>
>>  </resultMap>
>>
>>  <select id="getFamilies" resultMap="parentResult">
>>   select
>>     p.id AS parent_id,
>>     p.name AS parent_name,
>>     c.name AS child_name,
>>     c.desc AS description
>>   FROM child c, parent p
>>   WHERE p.id = c.parent_id
>> </select>
>> </sqlMap>
>>
>> In this example both the column and the property names
>> are ambiguous, but it's gracefully handled. :-)
>>
>> HTH,
>> Kris
>>
>>  --- Nathan Maves <Nathan.Maves@Sun.COM> wrote:
>>
>>> Great!  I will give it a try.
>>>
>>> What do you suggest when you have ambiguously
>>> defined column names in a
>>> n+1 query?
>>>
>>> nathan
>>> On Feb 9, 2005, at 10:30 AM, Clinton Begin wrote:
>>>
>>>> If you can join the data into a single resultset
>>>
>>> with repeating
>>>
>>>> groups, the N+1 solution will work, no matter how
>>>
>>> the collections are
>>>
>>>> arranged.
>>>>
>>>> As long as you group by some column in table_a,
>>>
>>> you can separately map
>>>
>>>> 2 collections on the same class.
>>>>
>>>> This will work.
>>>>
>>>> Try it out!
>>>>
>>>> Clinton
>>>>
>>>> On Wed, 09 Feb 2005 10:21:54 -0700, Nathan Maves
>>>> <Nathan.Maves@sun.com> wrote:
>>>>
>>>>> I dont think that the current implementation will
>>>>
>>> work for this but I
>>>
>>>>> was looking for some best practices on how to do
>>>>
>>> it.
>>>
>>>>>
>>>>> Parent Class A has n number of List properties
>>>>
>>> that all come for their
>>>
>>>>> own tables.
>>>>>
>>>>> A from table_a
>>>>>         List of B from table_b
>>>>>         List of C from table_c
>>>>>         .
>>>>>         .
>>>>>         .
>>>>>
>>>>>
>>>>> Nathan
>>>>>
>>>>>
>>>
>>>
>>
>>
>>     
>>     
>>        
>> ___________________________________________________________
>> ALL-NEW Yahoo! Messenger - all new features - even more fun! 
>> http://uk.messenger.yahoo.com
>
>
>



Mime
View raw message