ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Clinton Begin" <clinton.be...@gmail.com>
Subject RE: Handling 0..1 association?
Date Mon, 08 Oct 2007 15:44:00 GMT
That's weird....I thought for the join mapping that this would work fine.  


I thought the only time we had this problem was when lazy loading was
enabled and a separate select query was used....


Fearghal, can you post your SQL and result mappings?




From: Fearghal O Maolcatha [mailto:fearghal.omaolcatha@gmail.com] 
Sent: October-08-07 8:45 AM
To: user-java@ibatis.apache.org; lmeadors@apache.org
Subject: Re: Handling 0..1 association?


Larry, thanks for the info.

On 08/10/2007, Larry Meadors <lmeadors@apache.org> wrote:

You'll need to write a custom handler.

The reason is that since you are mapping SQL results to Java object,
iBATIS cannot know that there is no record - all it sees are the
results, not the underlying tables. 

Probably the simplest solution in this case is to do the query as you
are now, but in your DAO, look at the property in B that represents
the PK of table B - if it's null, set B to null.

It's a one liner: 

if(b.getPK() == null) a.setB(null);


On 10/8/07, Fearghal O Maolcatha <fearghal.omaolcatha@gmail.com> wrote:
> Hi,
> I have a class A that may or may not contain a reference to an associated 
> class B. I'm doing a left outer join between the table being represented
> class A and the table being represented by class B. If there is no match
> the table represented by class B then Ibatis still returns a reference to
> instance of class B with all properties set to their defaults. I would
> expected the reference to be set to null. Is there a way to achieve this
> behaviour (having the reference set to null when there is no corresponding

> instance), or do I need to write a customer handler?
> Regards,
> Fearghal.


View raw message