Mybatis dynamic prepend

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Mybatis dynamic prepend

Nikita Sahu
Hi,

I have recently upgraded from mybatis version 2 to 3.3.
Since mybatis 3.3.0 doesn't support dynamic prepend anymore, we tried to replace as shown below:

version 2 query

 delete FROM
    LFC_MULTI_SELECT_CODE
    where
    ID_UNIQUE_KEY = #{uniqueKey}
<dynamic prepend=" and ID_LFC_MULTI_SELECT_CODE not in">
    <if test="multiSelects != null">
        <isNotEmpty property="multiSelects">
          <iterate open=" (" close=") " conjunction="," property="multiSelects">
            <if test="multiSelects[].idMultiSelectCode != null">
              #{multiSelects[].idMultiSelectCode}
            </if>
          </iterate>
        </isNotEmpty>
    </if>
    </dynamic>


replaced it with :

 delete FROM
    LFC_MULTI_SELECT_CODE
    where
    ID_UNIQUE_KEY = #{uniqueKey}
    <if test="multiSelects != null and multiSelects.size() &gt; 0">
     and ID_LFC_MULTI_SELECT_CODE not in
    <foreach close=")" collection="multiSelects" index="index" item="item" open="(" separator=",">
            <if test="item != null and item.idMultiSelectCode != null">
#{item.idMultiSelectCode}
</if>
</foreach>
    </if>



The problem with this is 
If i have a list of not null DTOs(multiSelects) but the attribute of dto, which is being used in the query(idMultiSelectCode), is null, then in that case AND clause(  and ID_LFC_MULTI_SELECT_CODE not in) gets appended to the query with empty (), hence failing it.


This was working fine with dynamic prepend.

Any idea on this?


Thanks & Regards,
Nikita

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.