Search code examples
javaibatis

Ibatis getting collection of hashmaps


I'm using IBATIS 2.0, as it was what I was given. I'm trying to make my app read a collection of hashmaps, but it's giving me :

Exception: java.lang.ClassCastException: java.util.HashMap cannot be cast to java.util.Collection 

This is my resultmap:

<resultMap id="personnelDtlHM" class="java.util.HashMap">
<result property="idNo" column="ID"/>
<result property="fullName" column="FULL_NAME"/>
<result property="dteBirth" column="DTE_BIRTH"/>
<result property="addr" column="ADDR"/>
<result property="homeTelNo" column="HOME_TEL_NO"/>
<result property="mobileNo" column="HANDPHONE_NO"/>
<result property="emailAddr" column="EMAIL_ADDR"/>
</resultMap>

This is my query:

<select id="getMultiplePersInfo" resultMap="personnelDtlHM" parameterClass="list">
SELECT
  P.ID,
  P.FULL_NAME,
  P.DTE_BIRTH,
  P.ADDR,
  P.HOME_TEL_NO,
  P.HANDPHONE_NO,
  P.EMAIL_ADDR
  FROM
  PERS_TABLE P
  WHERE
  P.ID IN
  <iterate open="(" close=")" conjunction=",">
  #[]#
  </iterate>
</select>

This is my java code:

List<String> tmpNRICs = new ArrayList<String>();
if (records != null && records.size() > 0) {
String tempId = "A1234567D";
    tmpIDs.add(tempId);
}

Collection<HashMap> returnMapRecords = null;
SqlMapClient sqlMap = null;
String idList = "";
returnMapRecords = (Collection<HashMap>) sqlMap.queryForObject("getMultiplePersInfo", tmpIDs);

System.out.println(returnMapRecords.size());

The result is read properly, the hashmap is mapped properly, but I'm not getting the rows and rows of data. When I test with more than 1 ID number in tmpIDs, I receive the error:

java.sql.SQLException: Error: executeQueryForObject returned too many results.

I'm wondering if this is a very fundamental thing, as I do not believe such a powerful data mapper would not have the ability to map multiple rows. Yet, I am unable to find any answers on this, or am otherwise unable to comprehend the things I have found.

I am trying to retrieve the rows of data already in the database as such:

ID       | FULL_NAME | DTE_BIRTH | ADDR | HOME_TEL_NO | HANDPHONE_NO | EMAIL_ADDR
A1234567D|  TESTNAME | 12-12-2000| TEST | 1233465     | 12345678     | test@com.com
A2234567D| TESTNAME2 | 12-12-1999| TEST | 1234567     | 12345678     | test2@com.com
etc.

Thank you in advance for any help and suggestions.


Solution

  • Nvm I got it.

    Should have used sqlMap.queryForList() instead of sqlMap.QueryForObject()