ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary Bradshaw <gbrads...@davisvision.com>
Subject Map containing Lists of Maps
Date Wed, 09 Nov 2005 16:17:15 GMT
My compliments on a most useful product. I'm always thinking about ways to 
improve the signal-to-noise ratio in business software, and SqlMaps seems 
like a simple way to reuse a wide variety of familiar real-world Java 
objects by linking them directly to SQL parameters and results.

One of the first things to catch my eye was the ability to use Maps as 
parameters and result sets. I realize that a lot of the time you need a 
level of indirection between Java objects and SQL fields, and JavaBeans are 
a fine place for it, but if you don't need the indirection at this level in 
your architecture, usings Maps instead of JavaBeans could save a lot of 
otherwise useless code made up of nothing but thousands of getter and 
setter methods.

I tried a 1:N select the non-join way, and I found that everything worked 
as advertised when I mapped my primary result set to a Bean class. But when 
I tried to map it to a java.util.Map, I couldn't get iBatis to return the 
secondary objects as a java.util.List, even though I specified a javaType 
attribute in the primary result map. Can anyone tell me what I did wrong? 
Can I put a "[]" someplace or something?

<?xml version="1.0"?>
<!DOCTYPE sqlMap PUBLIC
  "-//iBATIS.com//DTD SQL Map 2.0//EN"
  "http://www.ibatis.com/dtd/sql-map-2.dtd">
<!-- Version 1 Release 0 Build 2 Update 4  -->
<!-- Built by ProDia.gram 2.0 on Tue Nov 08 08:44:10 EST 2005  -->
<sqlMap>
     <resultMap id="mapUserObject" class="Release">
         <result property="id" column="ID"/>
         <result property="description" column="DESCRIPTION"/>
         <result property="application" column="APPLICATION"/>
         <result property="version" column="VERSION"/>
         <result property="issueList" column="ID" select="getIssues"/>
     </resultMap>
     <resultMap id="mapToMap" class="java.util.HashMap">
         <result property="id" column="ID"/>
         <result property="description" column="DESCRIPTION"/>
         <result property="application" column="APPLICATION"/>
         <result property="version" column="VERSION"/>
         <result property="issueList" column="ID" select="getIssues"
          javaType="java.util.ArrayList"/>
     </resultMap>
     <select id="getNestedObjects" parameterClass="int"
      resultMap="mapUserObject">
         SELECT ID, APPLICATION, VERSION, DESCRIPTION FROM TEST.RELEASE
         WHERE ID = #value#
     </select>
     <select id="getNestedMaps" parameterClass="int"
      resultMap="mapToMap">
         SELECT ID, APPLICATION, VERSION, DESCRIPTION FROM TEST.RELEASE
         WHERE ID = #value#
     </select>
     <select id="getIssues" parameterClass="int"
      resultClass="java.util.HashMap">
         SELECT A.ISSUE_ID, DESCRIPTION FROM TEST.ISSUE AS A
         INNER JOIN TEST.ISSUE_RELEASE AS B ON (A.ID = B.ISSUE_ID)
         WHERE RELEASE_ID = #value#
     </select>
</sqlMap>

"getNestedObjects" works fine, but "getNestedMaps" returns a HashMap for 
the issueList property instead of an ArrayList, or it fails with 
"executeQueryForObject returned too many results" when there is more than 
one issue for a release. I read the documentation several times and I can't 
find anything that says that this shouldn't work, but I can't seem to make 
it happen.

Thanks in advance.

   - gary


------------------------------------------------------------------------
The information contained in this communication is intended
only for the use of the recipient(s) named above. It may
contain information that is privileged or confidential, and
may be protected by State and/or Federal Regulations. If
the reader of this message is not the intended recipient,
you are hereby notified that any dissemination,
distribution, or copying of this communication, or any of
its contents, is strictly prohibited. If you have received
this communication in error, please return it to the sender
immediately and delete the original message and any copy
of it from your computer system. If you have any questions
concerning this message, please contact the sender.
------------------------------------------------------------------------

Mime
View raw message