iBatis not populating object when there are no rows found.

Posted by Omnipresent on Stack Overflow See other posts from Stack Overflow or by Omnipresent
Published on 2009-11-10T19:23:13Z Indexed on 2010/04/08 15:43 UTC
Read the original article Hit count: 195

Filed under:
|
|

I am running a stored procedure that returns 2 cursors and none of them have any data. I have the following mapping xml:

<resultMap id="resultMap1" class="HashMap">
  <result property="firstName" columnIndex="2"/>
</resultMap>

<resultMap id="resultMap2" class="com.somePackage.MyBean">
  <result property="unitStreetName" column="street_name"/>
</resultMap>

<parameterMap id="parmmap" class="map">
  <parameter property="id" jdbcType="String" javaType="java.lang.String" mode="IN"/>
  <parameter property="Result0" jdbcType="ORACLECURSOR" javaType="java.sql.ResultSet" mode="OUT" resultMap="resultMap1"/>
  <parameter property="Result1" jdbcType="ORACLECURSOR" javaType="java.sql.ResultSet" mode="OUT" resultMap="resultMap2"/>
</parameterMap>

<procedure id="proc" parameterMap="parmmap">
    { call my_sp (?,?,?) }
</procedure>

First result set is being put in a HashMap...second resultSet is being put in a MyBean class.

code in my DAO follows:

HashMap map = new HashMap()
map.put("id", "1234");
getSqlMapClientTemplate().queryForList("mymap.proc", map);
HashMap result1 = (HashMap)((List)parmMap.get("Result0")).get(0);
MyBean myObject = (MyBean)((List)parmMap.get("Result1")).get(0);//code fails here

in the last line above..my code fails. It fails because second cursor has no rows and thats why nothing is put into the list. However, first cursor returns nothing as well but since results are being put into a HashMap the list for first cursor atleast has HashMap object inside it..

Why this difference? is there a way to make iBatis put an object of MyBean inside the list even if there are no rows returned? Or should I be handling this in my DAO...I want to avoid handling it in the DAO because I have whole bunch of DAO's like these.

© Stack Overflow or respective owner

Related posts about ibatis

Related posts about Oracle