ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Larry Meadors <larry.mead...@gmail.com>
Subject Re: Bidirectional associations and circular references
Date Wed, 10 Aug 2005 00:21:33 GMT
Hm, I am assuming this is something like an Order to OrderItem relationship.

I'll try not to preach too much about this, but I generally shy away
from these kinds of relationships, because they are rarely all that

You could do this with a RowHandler by joining Order+OrderItem into a
composite object (with an Order and an OrderItem in it).

Probably the easier way is in you DAO class, get the Order object,
then get the OrderItem objects, then iterate through the OrderItem
objects and set the Order on them to the parent. Not real elegant, but

Just curious: Why do you need this relationship in your objects?


On 8/9/05, Eric Blue <ericblue76@gmail.com> wrote:
> Hi,
>  I apoligize in advance if this problem has been addressed previously on
> this list.  But, I've come across a (more than likely) common situation
> where I have 2 Objects:
>  Object 1 has a m:n relationship to Object2
>  AND
>  Object 2 has a 1:1 relationship to Object1
>  In other words, Object1.getObject2List() returns a collection of Object2. 
> And Object2.getObject1() returns a single instance of Object1.  I quickly
> discovered the circular relationship problem and noticed the disclaimer in
> the SQLMaps doc Pg. 30.
>  Important! Currently the SQL Map framework does not automatically resolve
> circular relationships. Be
>  aware of this when implementing parent/child relationships (trees). An easy
> workaround is to simply define
>  a second result map for one of the cases that does not load the parent
> object (or vice versa), or use a join as
>  described in the "N+1 avoidance" solutions.
>  I did what the doc advised, and for Object1 (which fetches the collection
> of Object2) I simply made a "noParent" resultmap which excluded itself. 
> This works fine for now, but I'm curious if there are any other approaches. 
> And, wondering if this will be addressed in the near future.
>  Thanks!
>  P.S. iBATIS still rocks ;)

View raw message