mybatis读取函数游标如何映射为自定义对象

菠萝啊哈哈 发布于 2013/07/24 16:06
阅读 3K+
收藏 1

struts2+spring3+mybatis为框架:

1、自定义函数如下:

   

create or replace function fn_get_unit_workinfo_list(--返回车辆状态统计信息
   p_unitid number,                                  --车台ID
   p_begin_time varchar2,                            --查询的开始时间,格式为"yyyy-mm-dd",不需要指定时、分、秒
   p_end_time varchar2                               --查询的结束时间,格式为"yyyy-mm-dd",不需要指定时、分、秒
)return sys_refcursor
as
   l_retVal sys_refcursor;
begin
省略后面的内容,该函数返回的为游标。

2、mapper.xml

 

<select id="selectCarWorkInfo" parameterType="Map" statementType="CALLABLE">
		#{result,jdbcType=CURSOR,mode=OUT,javaType=java.sql.ResultSet}
		 ={call fn_get_unit_workinfo_list(  
         #{unitid,jdbcType=DECIMAL,mode=IN},  
         #{startTime,jdbcType=VARCHAR,mode=IN},
         #{endTime,jdbcType=VARCHAR,mode=IN}
         )
        }
	</select>
3、报错为:

 2013-07-24 14:13:13,211 [main] DEBUG [java.sql.Connection] - ooo Connection Opened
 2013-07-24 14:13:13,277 [main] ERROR [org.liteframework.core.dao.impl.GenericDaoMyBatis] - nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error querying database.  Cause: java.lang.ClassCastException: org.apache.ibatis.executor.statement.CallableStatementHandler cannot be cast to org.apache.ibatis.executor.statement.PreparedStatementHandler
### The error may exist in file [D:\eclipseWorkspace\driverBookTrade\build\classes\com\chinaGPS\driverBookTrade\model\mapper\CarWorkInfoMapper.xml]
### The error may involve com.chinaGPS.driverBookTrade.model.pojo.CarWorkInfo.selectCarWorkInfo
### The error occurred while executing a query
### Cause: java.lang.ClassCastException: org.apache.ibatis.executor.statement.CallableStatementHandler cannot be cast to org.apache.ibatis.executor.statement.PreparedStatementHandler; nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error querying database.  Cause: java.lang.ClassCastException: org.apache.ibatis.executor.statement.CallableStatementHandler cannot be cast to org.apache.ibatis.executor.statement.PreparedStatementHandler
### The error may exist in file [D:\eclipseWorkspace\driverBookTrade\build\classes\com\chinaGPS\driverBookTrade\model\mapper\CarWorkInfoMapper.xml]
### The error may involve com.chinaGPS.driverBookTrade.model.pojo.CarWorkInfo.selectCarWorkInfo
### The error occurred while executing a query
### Cause: java.lang.ClassCastException: org.apache.ibatis.executor.statement.CallableStatementHandler cannot be cast to org.apache.ibatis.executor.statement.PreparedStatementHandler
 请大家不吝赐教,先谢谢了。

加载中
0
晕dows
晕dows

直接


{call fn_get_unit_workinfo_list(  
         #{unitid,jdbcType=DECIMAL,mode=IN},  
         #{startTime,jdbcType=VARCHAR,mode=IN},
         #{endTime,jdbcType=VARCHAR,mode=IN}
         )
        }
resultType设置成sys_refcursor 对应的model类


0
菠萝啊哈哈
菠萝啊哈哈

这个问题已解决,将解决的方式贴出来:

<select id="selectAllCursor" parameterType="Map" statementType="CALLABLE">
          <![CDATA[
           {#{result,mode=OUT,jdbcType=CURSOR}= call fn_query_history_all(
             #{calletter,jdbcType=VARCHAR,mode=IN},
             #{startTime,jdbcType=TIMESTAMP,mode=IN},
             #{endTime,jdbcType=TIMESTAMP,mode=IN},
             #{speed,mode=IN}
             )
            }
            ]]>
    </select>

执行之后,得到map里面的resutl:

super.getSqlSessionTemplate()
                .selectList("selectAllCursor",map);
         if(map!=null && map.containsKey("result")){
            
             OracleResultSet set = (OracleResultSet) map.get("result");

         }

返回顶部
顶部