Sorry, I just have been more concise:

I'm not talking about simple key-value maps that represent a row in a table.  I 
need to create a Map of objects, not a List of objects.  I typically represent 
associations using a Map, that way I can easily find/remove objects using the 
key.

As an example, a User object could contain many Role objects.  The roles are 
held in a Map and the key is the Role identifier, in this case it would be 
something like roleCode.  The client can then say user.getRoles().get("CLERK"). 
 Or you could use user.isInRole("CLERK") - the method would be able to just use 
map.containsKey("CLERK"), instead of iterating through the List, casting each 
element to a Role object, and then examining the roleCode property.

IBATIS will only create associations if the setter method is a List or 
Collection.  I think a Map would require something else in the DTD to specify a 
key value.

E.G. Mapping - the key value is "roles" in the user ResultMap - it's cross 
linked to the "getUserRolesById" select mapping which is used to build UserRole 
objects through the "userRole" mapping.  This creates a role ArrayList contain 
UserRole objects, but I want a HashMap (or LinkedHashMap) containing UserRole 
objects keyed by the property roleCode (or the column ROLE_CODE).

  <resultMap id="user" class="pwgsc.arms.model.User">
    <result property="userId" column="USER_ID"/>
    <result property="lastName" column="LAST_NAME"/>
    <result property="firstName" column="FIRST_NAME"/>
        .... other properties
    <result property="roles" column="USER_ID" select="getUserRolesById"/>
  </resultMap>

  <resultMap id="userRole" class="pwgsc.arms.model.UserRole" extends="role">
    <result property="userId" column="USER_ID"/>
    <result property="effectiveDate" column="EFFECTIVE_DATE"/>
    <result property="endDate" column="END_DATE" />
  </resultMap>

  <select id="getUserRolesById" resultMap="userRole">
    SELECT rtrim(B.role_code) as role_code, B.description_english, 
B.description_french, rtrim(A.user_id) as user_id, A.effective_date, A.end_date
    FROM tb__ar_user_roles A, tb__ar_roles B 
    WHERE A.user_id=#value# AND A.role_code=B.role_code
  </select>

-----Original Message-----
From: Larry Meadors [mailto:[EMAIL PROTECTED]
Sent: Wednesday, June 29, 2005 10:39 AM
To: [email protected]
Subject: Re: Automatically Create Maps


Yes, there is.

On 6/29/05, Mike Fotiou <[EMAIL PROTECTED]> wrote:
>  
> Is there any way in IBATIS to create a Map via the XML file instead of a
> List/Collection?  This is possible programmatically using queryForMap.  If
> not, would it be useful in a future version of IBATIS?

Reply via email to