开发者社区> 问答> 正文

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

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
 请大家不吝赐教,先谢谢了。

展开
收起
爱吃鱼的程序员 2020-06-22 18:07:55 732 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    直接


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


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

    <selectid="selectAllCursor"parameterType="Map"statementType="CALLABLE">
           <![CDATA[
             {#{result,mode=OUT,jdbcType=CURSOR}=callfn_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")){
             
             OracleResultSetset=(OracleResultSet)map.get("result");

            }

    d
    2020-06-22 18:08:11
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Java Spring Boot开发实战系列课程【第6讲】:Spring Boot 2.0实战MyBatis与优化(Java面试题) 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载