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 Maarten Bosteels <mb...@gmail.com> on 2006/10/10 21:37:17 UTC

duplicate column names

Hello,

I found this example in the Developer Guide::

<resultMap id="get-product-result" class="com.ibatis.example.Product">
<result property="id" column="PRD_ID"/>
<result property="description" column="PRD_DESCRIPTION"/>
<result property="category" resultMap="get-category-result" />
</resultMap>

<resultMap id="get-category-result" class="com.ibatis.example.Category">
<result property="id" column="CAT_ID" />
<result property="description" column="CAT_DESCRIPTION" />
</resultMap>

<select id="getProduct" parameterClass="int" resultMap="get-product-result">
select *
from PRODUCT, CATEGORY
where PRD_CAT_ID=CAT_ID
and PRD_ID = #value#
</select>

What if the columns in PRODUCT and CATEGORY do not have the PRD_ and CAT_
prefixes and share column-names (eg ID) ?
It would most probably work to have a column alias for every column
but I would like to avoid that and stick with the star in "select *
from"

I am having a similar problem with RowMapper and Spring's JDBCTemplate
and wondered if iBatis has a solution.

Thanks, I hope my question is clear.

Maarten

Re: duplicate column names

Posted by Maarten Bosteels <mb...@gmail.com>.
I was afraid you were gonna say that :-)
It's too bad that this query

  select PRODUCT.*, CATEGORY.* from PRODUCT, CATEGORY where ...

does not yield column-names like
"PRODUCT.ID", "PRODUCT.DESCRIPTION", "CATEGORY.ID", ...

That's of course a short-coming of jdbc (or rather of SQL itself), not iBatis.

Maarten

On 10/11/06, Clinton Begin <cl...@gmail.com> wrote:
> No.
>
> This would be a impossible solution.  We can't arbitrairly map two columns
> with the same name, unless you wanted to do it by column number.  But that
> is also arbitrary with SELECT *.
>
> I'm afraid you're asking for the impossible.  I suggest you use aliases.
>
> Clinton
>
>
> On 10/10/06, Maarten Bosteels <mb...@gmail.com> wrote:
> > Hello,
> >
> > I found this example in the Developer Guide::
> >
> > <resultMap id="get-product-result" class="com.ibatis.example.Product">
> > <result property="id" column="PRD_ID"/>
> > <result property="description" column="PRD_DESCRIPTION"/>
> > <result property="category" resultMap="get-category-result" />
> > </resultMap>
> >
> > <resultMap id="get-category-result" class=" com.ibatis.example.Category">
> > <result property="id" column="CAT_ID" />
> > <result property="description" column="CAT_DESCRIPTION" />
> > </resultMap>
> >
> > <select id="getProduct" parameterClass="int"
> resultMap="get-product-result">
> > select *
> > from PRODUCT, CATEGORY
> > where PRD_CAT_ID=CAT_ID
> > and PRD_ID = #value#
> > </select>
> >
> > What if the columns in PRODUCT and CATEGORY do not have the PRD_ and CAT_
> > prefixes and share column-names (eg ID) ?
> > It would most probably work to have a column alias for every column
> > but I would like to avoid that and stick with the star in "select *
> > from"
> >
> > I am having a similar problem with RowMapper and Spring's JDBCTemplate
> > and wondered if iBatis has a solution.
> >
> > Thanks, I hope my question is clear.
> >
> > Maarten
> >
>
>

Re: duplicate column names

Posted by Clinton Begin <cl...@gmail.com>.
No.

This would be a impossible solution.  We can't arbitrairly map two columns
with the same name, unless you wanted to do it by column number.  But that
is also arbitrary with SELECT *.

I'm afraid you're asking for the impossible.  I suggest you use aliases.

Clinton

On 10/10/06, Maarten Bosteels <mb...@gmail.com> wrote:
>
> Hello,
>
> I found this example in the Developer Guide::
>
> <resultMap id="get-product-result" class="com.ibatis.example.Product">
> <result property="id" column="PRD_ID"/>
> <result property="description" column="PRD_DESCRIPTION"/>
> <result property="category" resultMap="get-category-result" />
> </resultMap>
>
> <resultMap id="get-category-result" class="com.ibatis.example.Category">
> <result property="id" column="CAT_ID" />
> <result property="description" column="CAT_DESCRIPTION" />
> </resultMap>
>
> <select id="getProduct" parameterClass="int"
> resultMap="get-product-result">
> select *
> from PRODUCT, CATEGORY
> where PRD_CAT_ID=CAT_ID
> and PRD_ID = #value#
> </select>
>
> What if the columns in PRODUCT and CATEGORY do not have the PRD_ and CAT_
> prefixes and share column-names (eg ID) ?
> It would most probably work to have a column alias for every column
> but I would like to avoid that and stick with the star in "select *
> from"
>
> I am having a similar problem with RowMapper and Spring's JDBCTemplate
> and wondered if iBatis has a solution.
>
> Thanks, I hope my question is clear.
>
> Maarten
>