Quantcast

Collections: getting Nested Results when using Nested Select

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Collections: getting Nested Results when using Nested Select

philomath
Hi, All-

I have a mapped type (A) which includes a collection of another mapped
type (B). I am using a Nested Select to obtain the collection of Bs in
my mapping for A. My results include the correctly selected B
collection, however, the collection also includes additional
(unexpected) type B instances.

Note that:
1) my base type mappings for A and B are both auto-generated from the
database schema and both have primary keys correctly identified by
"id" elements
2) there are column names that appear in both the A and B mappings
(the tables are fairly similar)

I realize from my results that the "extra" B instances in my
collection are artifacts from the query for type A, since A and B
share common field names and no attempt at distinction has been made.
I understand that I might alleviate this problem by aliasing columns
in my selects so all columns are uniquely named.

I would expect the result set for the A query to be used to create B
instance ***if I were using the Nested Results approach***. However, I
am using the Nested Select approach. If I am using Nested Select, why
am I getting Nested Results in my collection as well?

Am I missing something? Expecting too much from MyBatis? Any ideas
beyond column aliasing?

Many thanks! I hope this explanation was sufficiently clear without
posting mappings / code.

-Joe
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Collections: getting Nested Results when using Nested Select

Eduardo Macarron
Maybe this section in the doc clarifies the issue:
http://www.mybatis.org/core/sqlmap-xml.html#Auto-mapping
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Collections: getting Nested Results when using Nested Select

philomath
Eduardo, many thanks for the response. I have read this doc, but I
still do not think I am clear. I am using default (partial) auto
mapping, and the doc states that auto mapping will not apply in the
case of a nested mapping, which I am indeed using in my Nested Select.
Even if I had no auto mapping, my results columns are ambiguous since
A and B have explicit mappings from common column names. Auto or
explicit, I am still concerned that the result set for the A query is
used for B mapping when I am explicitly indicating that I want my B
results to come from the Nested Select, not the the A query results.

Again, my thanks.

On Apr 4, 11:51 am, Eduardo <eduardo.macar...  (Nested
Results)@gmail.com> wrote:
> Maybe this section in the doc clarifies the issue:http://www.mybatis.org/core/sqlmap-xml.html#Auto-mapping
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Collections: getting Nested Results when using Nested Select

Eduardo Macarron
If you are using manual mappings then it is not possible that results
from A are being applied to B and viceversa. Post your XML or much
better write a test to reproduce the case :)

http://code.google.com/p/mybatis/wiki/Test

El día 4 de abril de 2012 18:21, philomath <[hidden email]> escribió:

> Eduardo, many thanks for the response. I have read this doc, but I
> still do not think I am clear. I am using default (partial) auto
> mapping, and the doc states that auto mapping will not apply in the
> case of a nested mapping, which I am indeed using in my Nested Select.
> Even if I had no auto mapping, my results columns are ambiguous since
> A and B have explicit mappings from common column names. Auto or
> explicit, I am still concerned that the result set for the A query is
> used for B mapping when I am explicitly indicating that I want my B
> results to come from the Nested Select, not the the A query results.
>
> Again, my thanks.
>
> On Apr 4, 11:51 am, Eduardo <eduardo.macar...  (Nested
> Results)@gmail.com> wrote:
>> Maybe this section in the doc clarifies the issue:http://www.mybatis.org/core/sqlmap-xml.html#Auto-mapping
Loading...