ibatis-user-cs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bob Hanson" <mnbo...@gmail.com>
Subject Re: Instances integrity
Date Mon, 26 Jun 2006 20:16:06 GMT
This has nothing to do with iBatis. Object variables are actually just
references. By default, two objects are only considered equal if they are
both referencing the same object in memory. You need to override the Equals
method and then compare your objects using the id. (You should also override
GetHashCode as well)

On 6/26/06, Carlos Peix <peix-listas@praxia.com.ar> wrote:
>
> Hi all,
>
> I'm wondering how you manage with different instances of the same
> (conceptual)
> entity. As I tested, IBatis builds new instances on each query.
>
> This is causing me problems with the integrity of the domain model, for
> example,
> if I code:
>
> OperatingUnit firstInstance =
>   (OperatingUnit)Mapper.QueryForObject( "OperatingUnitById", 1 );
>
> OperatingUnit secondInstance =
>   (OperatingUnit)Mapper.QueryForObject( "OperatingUnitById", 1 );
>
> IBatis returns two different instances of the "same entity".
>
> or, if I have a OperatingUnit object and a Customer object and the
> Customer
> object has a reference to a OperatingUnit:
>
> OperatingUnit operatingUnit =
>   (OperatingUnit)Mapper.QueryForObject( "OperatingUnitById", 1 );
>
> Customer myCustomer =
>   (Customer)Mapper.QueryForObject( "CustomerById", 10 );
>
> ( myCustomer.OperatingUnit == operatingUnit ) will return false
>
> ( myCustomer.OperatingUnit.Id == operatingUnitId ) will return true
>
> Of course, the problem gets very ugly if you modifiy both instances.
>
> How do you handle this?
>
> Thanks
>
> Carlos
>
>

Mime
View raw message