ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Larry Meadors" <lmead...@apache.org>
Subject Re: Handling 0..1 association?
Date Mon, 08 Oct 2007 14:34:00 GMT
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);

Larry


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 by
> class A and the table being represented by class B. If there is no match in
> the table represented by class B then Ibatis still returns a reference to an
> instance of class B with all properties set to their defaults. I would have
> 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.
>
>

Mime
View raw message