ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hongbo HE <h...@yahoo.com>
Subject Re: 1:1 with abstract class
Date Thu, 10 Nov 2005 02:19:39 GMT
Please see my sqlMap file below, I have tried to use a
resultmap inside a resultmap, but it returns a list.
If entity is a concrete class, I can use the
dot.notation <result property="entity.id"
column="entityId">, for abstract class, I can include
the extra column "type" in the resultSet of the sql,
but how to tell the resultMap of orderResult to
instantiate a student or a insturctor instead of a
entity?

<sqlMap namespace="OrderEntry">

    <typeAlias alias="order"
type="com.test.model.Order"/>
    <typeAlias alias="entity"
type="com.test.model.Entity"/>
    <typeAlias alias="student"
type="com.test.model.Student"/>
    <typeAlias alias="instructor"
type="com.test.model.Instructor"/>


<resultMap id="orderResult" class="order">
	<result property="id" column="id"/>
        <result property="<"
resultMap="OrderEntry.entityResult" 
</resultMap>

<resultMap id="entityResult" class="entity">
	<result property="id" column="id"/>
	<discriminator column="type" javaType="integer" >
	 <subMap value="1" resultMap="studentResult"/>
	 <subMap value="2" resultMap="instructorResult"/>
	</discriminator>
</resultMap>
<resultMap id="studentResult" class="student"
extends="entityResult">
</resultMap>
<resultMap id="instructorResult" class="instructor"
extends="ownerResult">
</resultMap>


--- Gilles Bayon <ibatis.net@gmail.com> wrote:

> You sould use the discriminator tag
> 
> On 11/9/05, Gilles Bayon <ibatis.net@gmail.com>
> wrote:
> >
> > Yould use the discriminator tag
> >
> > On 11/9/05, Hongbo HE <h_he@yahoo.com> wrote:
> > >
> > > I have a 1:1 relation of 2 tables. Multiple
> subClasses
> > > is mapped to one of them
> > >
> > > Order
> > > (id,
> > > entityId,
> > > ...
> > > )
> > >
> > > Entity
> > > (id,
> > > type,
> > > ...
> > > )
> > >
> > > type is the discriminator.
> > >
> > > Order {
> > > long id;
> > > Entity entity;
> > > }
> > >
> > > abstract Entity {
> > > long id;
> > > }
> > >
> > > Instructor extends Entity {
> > > }
> > >
> > > Student enxteds Entity {
> > > }
> > >
> > > I'd like to get an order together with its
> entity
> > > either Instructor or Student, I can't use the
> > > dot.notation.to.specify.the.properties, since
> > > it will try to instantiante an Entity class,
> which
> > > is not I wanted.
> > >
> > > Any help is greatly appreciated,
> > >
> > > Hongbo
> > >
> > >
> > >
> > > __________________________________
> > > Yahoo! FareChase: Search multiple travel sites
> in one click.
> > > http://farechase.yahoo.com
> > >
> >
> >
> 



	
		
__________________________________ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com

Mime
View raw message