oracle - How to configure MyBatis mapper for cursor as an output parameter? -
oracle stored procedure:
create or replace procedure "tgt_mpd_planogram_sel_sp" ( pog_num_in in varchar2, plan_data_sel_cur out sys_refcursor, sql_code_out out number, sql_err_msg_out out varchar2) ...
mapper.xml
<select id="getplanograms" statementtype="callable" parametertype="com.tgt.snp.pog.vo.planogramsearchvo" resultmap="mapresultplanogram"> { call tgt_mpd_planogram_sel_sp( #{pog_num_in,javatype=string,jdbctype=varchar,jdbctypename=varchar2,mode=in}, #{plan_data_sel_cur,jdbctype=cursor,resultmap=mapresultplanogram,mode=out}, #{sql_code_out,javatype=integer,jdbctype=integer,jdbctypename=integer,mode=out}, #{sql_err_msg_out,javatype=string,jdbctype=varchar,jdbctypename=varchar2,mode=out} ) } </select>
vo object
public class planogramsearchvo { public planogramsearchvo(){} public string getpog_num_in() { return pog_num_in; } public void setpog_num_in(string pog_num_in) { this.pog_num_in = pog_num_in; } private string pog_num_in; public resultset getplan_data_sel_cur() { return plan_data_sel_cur; } public void setplan_data_sel_cur(resultset plan_data_sel_cur) { this.plan_data_sel_cur = plan_data_sel_cur; } private resultset plan_data_sel_cur; public integer getsql_code_out() { return sql_code_out; } public void setsql_code_out(integer sql_code_out) { this.sql_code_out = sql_code_out; } private integer sql_code_out; public string getsql_err_msg_out() { return sql_err_msg_out; } public void setsql_err_msg_out(string sql_err_msg_out) { this.sql_err_msg_out = sql_err_msg_out; } private string sql_err_msg_out; }
error message
caused by: org.springframework.jdbc.uncategorizedsqlexception: ### error querying database. cause: java.sql.sqlexception: non supported sql92 token @ position: 1: ### error may exist in class path resource [planogrammapper.xml] ### error may involve com.tgt.snp.pog.mapper.planogrammapper.getplanograms-inline ### error occurred while setting parameters ### sql: { ?, ?, ? = call tgt_mpd_planogram_sel_sp( ? ) } ### cause: java.sql.sqlexception: non supported sql92 token @ position: 1: ; uncategorized sqlexception sql []; sql state [99999]; error code [17034]; non supported sql92 token @ position: 1: ; nested exception java.sql.sqlexception: non supported sql92 token @ position: 1:
please point out did wrong? in advance.
the <select>
element not need resultmap
attribute because not used here: calling procedure out parameters, if cursor/resultset, not select.
you may need specify java type result set in parameter definition:
#{plan_data_sel_cur, jdbctype=cursor, javatype=java.sql.resultset, resultmap=mapresultplanogram, mode=out}
the property plan_data_sel_cur in class planogramsearchvo
must not java.sql.resultset
rather list<planogram>
if the result map mapresultplanogram
maps cursor results planogram
object.
mybatis doing work of fetching/mapping resultset/cursor list of objects; drawback control returned when cursor fetched: no custom result handling, lazy/differed loading, ... have answered question this.
Comments
Post a Comment