You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-cs@ibatis.apache.org by Bob Hanson <mn...@gmail.com> on 2007/02/27 18:55:28 UTC

ResultMap feature request (assigning circular reference after groupBy mapping has completed)

I'm posting this to the user list to see if this is something others
would want before opening a JIRA request.

I currently have a mapping case which has a circular reference. My
current ReferenceMap looks like:
    <resultMap id="ApplicationResultMap" class="Application" groupBy="Id">
      <result property="Id" column="ApplicationId"/>
      <result property="Name" column="ApplicationName"/>
      <result property="DefaultRole" resultMapping="Role.DefaultRoleResultMap"/>
      <result property="Users" resultMapping="User.ApplicationUserResultMap"/>
      <result property="Roles" column="ApplicationId"
select="SelectApplicationRoles"/>
    </resultMap>

The circular reference is Application -> Users -> Application. My
ApplicationClass contains a list of ApplicationUsers. An
ApplicationUser has a reference to its Application.

I map an Application object using two nested groupBy result maps
(ApplicationResultMap grouped by ApplicationId and
ApplicationUserResultMap grouped by UserId).

The mapping  works correctly and after I'm done my objects are built
correctly with one exception: My ApplicationUser objects do not have a
reference to their containing Application.

I haven't used a RowDelegate before but I don't believe it would help
me in this case because the object available to me in the RowDelegate
would not have anything to do with the Application object that is
created as part of the groupBy mapping.

Thus I think what I need would be either of the following:
1. a new type of "GroupByRowDelegate" which would contain objects
already created in the groupBy in addition to the current object being
created.

public delegate void GroupByRowDelegate(object obj, IList
groupByObjects, IList list);

2. a new resultMap element that would let me assign references after
mapping has completed. Something like:
<resultAssign fromResultProperty="Id", toResultProperty="Users.Application" />

resultAssign elements would be processed after mapping has been
completed. fromResultProperty would need to map to a single instance.
The value before the period in toResultProperty can either be a single
instance or a list and iBatis would handle either case (assign to the
single instance, or assign to all members of the list).

So after all of that does anyone have some comments? :) A
GroupByRowDelegate would probably be the cleanest solution but I'm
assuming that the objects are created in a specific order which would
have to be defined.