You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ibatis.apache.org by "Perry Nguyen (JIRA)" <ib...@incubator.apache.org> on 2005/12/13 03:40:45 UTC

[jira] Commented: (IBATIS-225) Reuse resultmap for single bean property

    [ http://issues.apache.org/jira/browse/IBATIS-225?page=comments#action_12360278 ] 

Perry Nguyen commented on IBATIS-225:
-------------------------------------

I, too, have a somewhat related problem.

I have interfaces for all of my domain objects, thus, I have something like this contrived example:

interface Person {
  Address getAddress/setAddress
  String getName/setName
}

interface Address {
  String getStreetName/setStreetName
}

class ConcretePerson {
  // implement Person interface
}
class ConcreteAddress {
 // implement Address interface
}

Person and Address are in a 1:1 relationship.

Say I want to load the address object in a join with person, how do I do that?

<resultMap id="myResult" class="ConcretePerson">
  <result property="name" column="PERSON_NAME"/>
  <result property="address.streetName" column="ADDR_ST_NAME"/>
</resultMap>
<!-- using the above resultMap results in an InstantiationException because Address is an interface -->

<select ... resultMap="myResult">
  select p.name as person_name, a.name as addr_st_name
  from person p, address a
  where p.addr_id = a.id
</select>

Alternatively, I tried
<resultMap id="myResult" class="ConcretePerson">
  <result property="name" column="PERSON_NAME"/>
  <result property="address" resultMap="myAddrResult"/>
</resultMap>
<resultMap id="myAddrResult" class="ConcreteAddress">
  <result property="streetName" column="ADDR_ST_NAME"/>
</resultMap>

This results in an instantiation exception as well, except it's in the list generating code.

> Reuse resultmap for single bean property
> ----------------------------------------
>
>          Key: IBATIS-225
>          URL: http://issues.apache.org/jira/browse/IBATIS-225
>      Project: iBatis for Java
>         Type: Improvement
>   Components: SQL Maps
>     Reporter: Huy Do

>
> Allow the following reuse of result maps
> <resultMap id="Pick" class="package.domain.Pick">
>   <result property="pickId" column="pick_id"/>
>    <result property="sale" resultMap="Sale"/>
> </resultMap>
> <resultMap id="Sale" class="Sale">
>    <result column="sale_id" property="saleId"/>
> </resultMap>
> with beans
> class Pick {
>       String pickId;
>       Sale sale;
> }
> class Sale {
>       String saleId;
> }
> At the moment <result property="sale" resultMap="Sale"/> can only be reused if property "sale" is a collection.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira