ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Larry Meadors" <lmead...@apache.org>
Subject Re: how to resolve same column/property name when reusing resultMap
Date Mon, 12 Feb 2007 18:50:44 GMT
You don't have to - you can alias it in the SQL using the syntax
Carlos provided.

Larry


On 2/12/07, Peng Wang <wpcfan@gmail.com> wrote:
> 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
> > 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