I'm using iBATIS to call a Stored Procedure on MSSQL Server, the input parameters are properties on a POJO that is put to the map:
Map<String, Object> saveMap = new HashMap<String, Object>();
saveMap.put("obj", myArticle);
update("save", saveMap);
All parameters are set correctly as input to the procedure so nothing wrong there. But one of the parameters is a output-parameter and and I was expecting it to be set back to the POJO but instead one extra mapping "obj.new"=false
is put the map by iBATIS.
Here's a simplified version of the mapping showing the basic idea:
<procedure id="save">
{<include refid="Core.returned_value" />
CALL SPRC_ARTICLE_NAME_SAVE (
<include refid = "Core.common_fields" />
@pArticle_id = #obj.art_id#
, @pArtname = #obj.artname#
, @pNewArticleName_flg = #obj.new,mode=INOUT#
)}
</procedure>
After calling the procedure I have two mappings in Map passed to iBATIS:
"obj"=POJO
"obj.new"=False
Now I see that iBatis documentation saids "When executing stored procedures – iBATIS will create objects for OUTPUT parameters" so it makes sense. But my question is if there a way to instruct iBATIS put back the boolean value to the POJO after the procedure is called? I rather don't do the extra work of getting the value out of the map and set it to the POJO my self.
// Uhlén
to call a stored procedure usgin mybatis/ibatis 3 you will have to follow some tips: must set the statement type to callable. must use the jdbc standard escape sequence for stored procedures: { call xxx (parm1, parm2) } must set the mode of all parameters ( in, out, inout )
The Output Parameters in Stored Procedures are used to return some value or values. A Stored Procedure can have any number of output parameters. The simple logic is this — If you want to return 1 value then use 1 output parameter, for returning 5 values use 5 output parameters, for 10 use 10, and so on.
Output parameter is a parameter whose value is passed out of the stored procedure/function module, back to the calling PL/SQL block. An OUT parameter must be a variable, not a constant. It can be found only on the left-hand side of an assignment in the module.
You can using an explicit parameter map. See Page 21 of the manual
Its rather verbose but its worked for me in the past.
<parameterMap id="swapParameters" class="map" >
<parameter property="email1" jdbcType="VARCHAR" javaType="java.lang.String" mode="INOUT"/>
<parameter property="email2" jdbcType="VARCHAR" javaType="java.lang.String" mode="INOUT"/>
</parameterMap>
<procedure id="swapEmailAddresses" parameterMap="swapParameters" >
{call swap_email_address (?, ?)}
</procedure>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With