I'm not sure about the ultimate answer, but I'm also not sure the
following is valid:

<result column="parent_column_1" property="children"
resultMap="childResultMap" select="loadChildren"/>

I believe the "resultMap" and "select" attributes are mutually
exclusive  ("resultMap" for avoiding N+1 selects, and "select" for
sub-selects, which in turn have their own resultMaps).

Also, at risk of hijacking the thread, I just have to throw in my two cents:

Call me a coward, but hashtables inside hashtables as a domain model
frightens the living daylights out of me.  We've just inherited a web
app that uses this "design pattern" and we quickly bestowed the
honorable title of "trashtable" to the idiom.  Perhaps I'm just
entrenched in my ways, but I prefer POJOs and the ability to really
lean on the compiler (thus my biggest gripe about JSP/Struts tags).  I
would love to hear about any compelling arguments for the hash-in-hash
model in an off-topic thread.

Ted

On 27/03/07, Utkarsh Ahuja <[EMAIL PROTECTED]> wrote:
Hi,
I am trying to create nested HashMaps something like

ParentHashMap {
     ...... some key value pairs
     ......
     childHashMap....some key value pairs
}

I am doing the following:

     <resultMap id="parentResultMap" class="java.util.HashMap">
        <result column="parent_column_1" property="parentColumn1" />
        <result column="parent_column_1" property="parentColumn2" />
        <result column="parent_column_1" property="parentColumn3" />
        <!-- customizations -->
        <result column="parent_column_1" property="children"
resultMap="childResultMap" select="loadChildren"/>
    </resultMap>

    <select id="loadParent" parameterClass="java.util.HashMap"
resultMap="parentResultMap">
        select
            parent_column_1,
            parent_column_2,
             parent_column_3
        from parent
    </select>

    <resultMap id="childResultMap" class="java.util.HashMap">
        <result column="child_column_1" property="childColumn1" />
        <result column="child_column_2" property="childColumn2" />
        <result column="child_column_3" property="childColumn3" />
        <result column="parent_column_1" property="parentColumn1" />
    </resultMap>

    <select id="loadChildren" resultMap="childResultMap">
        select
           child_column_1,
           child_column_2,
           child_column_3,
            parent_column_1
         from child
        where parent_column_1 = #parentColumn1:VARCHAR#
    </select>

Can iBatis instantiate and create a HashMap within another HashMap and use
the property element as the key for it ?
<result column="parent_column_1" property="children"
resultMap="childResultMap" select="loadChildren"/>

Thanks
Utkarsh








Reply via email to