Uhlen
Uhlen

Reputation: 1778

Stored procedure output parameter set back to POJO by iBATIS

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:

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

Upvotes: 20

Views: 4482

Answers (1)

chotchki
chotchki

Reputation: 4343

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>

Upvotes: 1

Related Questions