ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Peng Wang" <wpc...@gmail.com>
Subject Re: how to resolve same column/property name when reusing resultMap
Date Tue, 13 Feb 2007 00:29:28 GMT
thanks, I got it, I thought the column in iBatis was real column name, sorry
for the stupid question

On 2/13/07, Carlos Cajina - Hotmail 1 <cecajina@hotmail.com> wrote:
>
>  Hi again Peng.
>
> As you can see from my example, the column name remains the same, you'll
> just have to keep aliasing it in your SQL statements son that iBATIS doesn't
> "get confused"...
>
>
> ----- Original Message -----
> *From:* Peng Wang <wpcfan@gmail.com>
> *To:* user-java@ibatis.apache.org
>  *Sent:* Monday, February 12, 2007 11:18 AM
> *Subject:* Re: how to resolve same column/property name when reusing
> resultMap
>
>
> thanks, but what if the legacy database has the field name id and we
> cannot change that?
>
> On 2/12/07, Carlos Cajina <cecajina@hotmail.com> wrote:
> >
> >  Hi Peng.
> >
> > I think you can try something like this:
> >
> > <resultMap id="testPlanResult" class="TestPlan" groupBy="id">
> >     <result property="id" column="id"/>
> >     <result property="version" column="version"/>
> >     <result property="name" column="name"/>
> >     <result property="createdDate" column="createdDate" javaType="
> > java.util.Date" />
> >     <result property="release" resultMap=" Release.releaseResult"/>
> > </resultMap>
> >
> > <resultMap id="releaseResult" class="Release" >
> >     <result property="id" column="* r_id*"/>
> >     <result property="version" column="version"/>
> >     <result property="name" column="name"/>
> >  </resultMap>
> >
> >
> > <select id="findTestPlans" resultMap="testPlanResult">
> >     select
> >      tp.id as id,
> >      tp.version as version,
> >      tp.name as name,
> >      tp.createdDate as createdDate,
> >      r.id as *r_id*
> >     from TestPlan tp left join release r on tp.release = r.name
> >   </select>
> >
> > Hope it helps.
> >
> > Regards,
> >
> > Carlos
> >
> > ----- Original Message -----
> > *From:* Peng Wang <wpcfan@gmail.com>
> > *To:* user-java@ibatis.apache.org
> > *Sent:* Monday, February 12, 2007 3:37 AM
> > *Subject:* how to resolve same column/property name when reusing
> > resultMap
> >
> >
> > Hi All,
> >
> > I am wondering how we can resolve the following naming issues.
> > Suppose we have two objects TestPlan and Release, both of them have a
> > field named id. If we want to reuse the resultMap, what should we do when we
> > create a query against these tables since both tables have the field id, is
> > there any way in iBatis to identify which field should be mapped to which
> > object?
> >
> > Thanks in advance,
> > -Peng
> >
> > <resultMap id="testPlanResult" class="TestPlan" groupBy="id">
> >     <result property="id" column="id"/>
> >     <result property="version" column="version"/>
> >     <result property="name" column="name"/>
> >     <result property="createdDate" column="createdDate" javaType="
> > java.util.Date" />
> >     <result property="release" resultMap=" Release.releaseResult"/>
> > </resultMap>
> >
> >  <resultMap id="releaseResult" class="Release" >
> >     <result property="id" column="id"/>
> >     <result property="version" column="version"/>
> >     <result property="name" column="name"/>
> >  </resultMap>
> >
> >
> > <select id="findTestPlans" resultMap="testPlanResult">
> >     select
> >      tp.id as id,
> >      tp.version as version,
> >      tp.name as name,
> >      tp.createdDate as createdDate,
> >       r.id as ?????
> >     from TestPlan tp left join release r on tp.release = r.name
> >   </select>
> >
> >
>

Mime
View raw message