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 rtrip <rt...@mailinator.com> on 2009/09/04 20:43:26 UTC

Bidirectional association in iBATIS 3?

This may have been asked a couple of times, but I haven't seen a useful
answer yet. My domain model has a parent-child relationship, but the child
also needs to have a reference to the parent object. Something like

Group {
     int groupId;
     String groupName;
     List<Item> items;
     .....
     .....
}

Item {
    int itemId;
    String itemName;
    Group parentGroup;
    ....;
}


How do I express this relationship in a resultMap? I tried the following,
but it gives me a StackOverflowError when I try to run a <select> query with
a join between the Group and Item tables:

    <resultMap id="groupMap" type="GroupDTO">
        <id property="groupId" column="groupId"/>
        <collection property="items" resultMap="itemMap"/>
    </resultMap>
    
    <resultMap id="itemMap" type="ItemDTO">
            <id property="itemId" column="itemId"/>
            <result property="objectId" column="objectId"/>
            <result property="objectType" column="objectType"/>
            <association property="parentGroup" column="groupId"
resultMap="groupMap"/>
    </resultMap>

I'm sure I'm doing something wrong here with the circular reference, but I
don't know what's the right way to do this. I have seen statements on this
list referring to this issue being solved by the iBATIS cache, but I'm not
sure how. Can anyone help, or point me to the solution? (Hibernate does this
kind of stuff easily, but sucks for many other reasons)

Thanks

- rtrip
-- 
View this message in context: http://www.nabble.com/Bidirectional-association-in-iBATIS-3--tp25299690p25299690.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: Bidirectional association in iBATIS 3?

Posted by Clinton Begin <cl...@gmail.com>.
PS:  Please include the exception as well.

Clinton

On Fri, Sep 4, 2009 at 2:05 PM, Clinton Begin <cl...@gmail.com>wrote:

> A stack overflow is most likely a bug in iBATIS.  Can you create a simple
> unit test (HSQLDB or Derby/JavaDB) and create a Jira ticket for it?
>
> I believe we have unit tests to cover this case, but your code must test
> the framework in a new way.
>
> Thanks much.
>
> Clinton
>
>
> On Fri, Sep 4, 2009 at 12:43 PM, rtrip <rt...@mailinator.com> wrote:
>
>>
>> This may have been asked a couple of times, but I haven't seen a useful
>> answer yet. My domain model has a parent-child relationship, but the child
>> also needs to have a reference to the parent object. Something like
>>
>> Group {
>>     int groupId;
>>     String groupName;
>>     List<Item> items;
>>     .....
>>     .....
>> }
>>
>> Item {
>>    int itemId;
>>    String itemName;
>>    Group parentGroup;
>>    ....;
>> }
>>
>>
>> How do I express this relationship in a resultMap? I tried the following,
>> but it gives me a StackOverflowError when I try to run a <select> query
>> with
>> a join between the Group and Item tables:
>>
>>    <resultMap id="groupMap" type="GroupDTO">
>>        <id property="groupId" column="groupId"/>
>>        <collection property="items" resultMap="itemMap"/>
>>    </resultMap>
>>
>>    <resultMap id="itemMap" type="ItemDTO">
>>            <id property="itemId" column="itemId"/>
>>            <result property="objectId" column="objectId"/>
>>            <result property="objectType" column="objectType"/>
>>            <association property="parentGroup" column="groupId"
>> resultMap="groupMap"/>
>>    </resultMap>
>>
>> I'm sure I'm doing something wrong here with the circular reference, but I
>> don't know what's the right way to do this. I have seen statements on this
>> list referring to this issue being solved by the iBATIS cache, but I'm not
>> sure how. Can anyone help, or point me to the solution? (Hibernate does
>> this
>> kind of stuff easily, but sucks for many other reasons)
>>
>> Thanks
>>
>> - rtrip
>> --
>> View this message in context:
>> http://www.nabble.com/Bidirectional-association-in-iBATIS-3--tp25299690p25299690.html
>> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
>> For additional commands, e-mail: user-java-help@ibatis.apache.org
>>
>>
>

Re: Bidirectional association in iBATIS 3?

Posted by Clinton Begin <cl...@gmail.com>.
A stack overflow is most likely a bug in iBATIS.  Can you create a simple
unit test (HSQLDB or Derby/JavaDB) and create a Jira ticket for it?

I believe we have unit tests to cover this case, but your code must test the
framework in a new way.

Thanks much.

Clinton

On Fri, Sep 4, 2009 at 12:43 PM, rtrip <rt...@mailinator.com> wrote:

>
> This may have been asked a couple of times, but I haven't seen a useful
> answer yet. My domain model has a parent-child relationship, but the child
> also needs to have a reference to the parent object. Something like
>
> Group {
>     int groupId;
>     String groupName;
>     List<Item> items;
>     .....
>     .....
> }
>
> Item {
>    int itemId;
>    String itemName;
>    Group parentGroup;
>    ....;
> }
>
>
> How do I express this relationship in a resultMap? I tried the following,
> but it gives me a StackOverflowError when I try to run a <select> query
> with
> a join between the Group and Item tables:
>
>    <resultMap id="groupMap" type="GroupDTO">
>        <id property="groupId" column="groupId"/>
>        <collection property="items" resultMap="itemMap"/>
>    </resultMap>
>
>    <resultMap id="itemMap" type="ItemDTO">
>            <id property="itemId" column="itemId"/>
>            <result property="objectId" column="objectId"/>
>            <result property="objectType" column="objectType"/>
>            <association property="parentGroup" column="groupId"
> resultMap="groupMap"/>
>    </resultMap>
>
> I'm sure I'm doing something wrong here with the circular reference, but I
> don't know what's the right way to do this. I have seen statements on this
> list referring to this issue being solved by the iBATIS cache, but I'm not
> sure how. Can anyone help, or point me to the solution? (Hibernate does
> this
> kind of stuff easily, but sucks for many other reasons)
>
> Thanks
>
> - rtrip
> --
> View this message in context:
> http://www.nabble.com/Bidirectional-association-in-iBATIS-3--tp25299690p25299690.html
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org
>
>