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 Perry Nguyen <pf...@hanhuy.com> on 2005/12/13 03:55:30 UTC
Interfaces for domain objects and resultMaps, how??
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 the exception
occurs while attempting to populate a List for the address property.
Are there any solutions for this? IBATIS-225 looks promising, but that
is so far down in the list and this problem is blocking me currently...
Re: Interfaces for domain objects and resultMaps, how??
Posted by Perry Nguyen <pf...@hanhuy.com>.
Larry,
I suppose you're right, the interfaces were an anachronism from the
older design, I think I can refactor the bean interfaces to be the bean
classes now...
Perry Nguyen wrote:
> Well,
>
> My situation's a bit complicated, but it has to do with abstracting what
> I had for previous entity beans, etc.
>
> Larry Meadors wrote:
>
>> Why are you using interfaces for beans?
Re: Interfaces for domain objects and resultMaps, how??
Posted by Perry Nguyen <pf...@hanhuy.com>.
Well,
My situation's a bit complicated, but it has to do with abstracting what
I had for previous entity beans, etc.
Larry Meadors wrote:
> Why are you using interfaces for beans?
>
> Larry
>
>
> On 12/12/05, Perry Nguyen <pf...@hanhuy.com> wrote:
>
>>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 the exception
>>occurs while attempting to populate a List for the address property.
>>
>>Are there any solutions for this? IBATIS-225 looks promising, but that
>>is so far down in the list and this problem is blocking me currently...
>>
>>
Re: Interfaces for domain objects and resultMaps, how??
Posted by Larry Meadors <lm...@apache.org>.
Why are you using interfaces for beans?
Larry
On 12/12/05, Perry Nguyen <pf...@hanhuy.com> wrote:
> 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 the exception
> occurs while attempting to populate a List for the address property.
>
> Are there any solutions for this? IBATIS-225 looks promising, but that
> is so far down in the list and this problem is blocking me currently...
>
>