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 Daniel Pitts <Da...@cnet.com> on 2006/03/29 21:09:59 UTC
Table alias in results map.
I want to perform a query like:
<select id="getData" resultClass="map" parameterClass="string">
Select * FROM data AS `root:data` JOIN other AS `root:other` JOIN
something as `root:other:something` WHERE $where$
</select>
The tables "data", "other", and "something" may or may not have
similarly named columns. The aliases correspond to bean's in a map.
---CODE---
Map myQuery = new HashMap();
myQuery.put("root:data" = new DataBean());
myQuery.put("root:other" = new OtherBean());
myQuery.put("root:other:something" = new SomethingBean());
sqlMap.queryForObject("getData", where, myQuery);
----------
Unfortunately, ibatis seems to look only at the column name, not the
table name. I would use result maps, but the query is way to dynamic.
My current kludge aliases EVERY column. This works, but is a somewhat
painful hack of introspection, and may be a performance bottleneck.
Is there any way to tell ibatis to use the table names as part of the
result map?
Much thanks in advance.
Daniel.
Re: Table alias in results map.
Posted by Jeff Butler <je...@gmail.com>.
Short answer - no.
Only the column name is returned in the result set. This is JDBC, not just
iBATIS. Run the query in something like the Squirrel SQL client to verify.
A better solution would be to use a real domain object instead of a map, and
use iBATIS' group by and descriminator support.
Jeff Butler
On 3/29/06, Daniel Pitts <Da...@cnet.com> wrote:
>
> I want to perform a query like:
> <select id="getData" resultClass="map" parameterClass="string">
> Select * FROM data AS `root:data` JOIN other AS `root:other` JOIN
> something as `root:other:something` WHERE $where$
> </select>
>
> The tables "data", "other", and "something" may or may not have
> similarly named columns. The aliases correspond to bean's in a map.
> ---CODE---
> Map myQuery = new HashMap();
> myQuery.put("root:data" = new DataBean());
> myQuery.put("root:other" = new OtherBean());
> myQuery.put("root:other:something" = new SomethingBean());
>
> sqlMap.queryForObject("getData", where, myQuery);
> ----------
>
> Unfortunately, ibatis seems to look only at the column name, not the
> table name. I would use result maps, but the query is way to dynamic.
>
> My current kludge aliases EVERY column. This works, but is a somewhat
> painful hack of introspection, and may be a performance bottleneck.
>
> Is there any way to tell ibatis to use the table names as part of the
> result map?
>
> Much thanks in advance.
> Daniel.
>