foreachmybatissqlmap

Element type "foreach" must be declared - mybatis


Is using foreach attribute in mybatis/ibatis for oracle sql updates a best practice? Below is my query in the sql map.

<update id="updateFG"  parameterClass="java.util.Map">
    
        <foreach collection="entries.entrySet()" item="item" index="index" >
            UPDATE <<tablename>>
            SET description = #{item.value},
                last_mod_date= SYSDATE
            WHERE name = #{item.key}
        </foreach>
        
    </update>

When I try to run this piece of code it is throwing me an error:

Error parsing XML. Cause: org.xml.sax.SAXParseException; lineNumber: 49; columnNumber: 72; Element type "foreach" must be declared.


Solution

  • Okay so when I changed my DCOTYPE from sqlmap to mapper - it worked fine.. I think foreach cannot be used for sqlMap..

    EDIT: realized the foreach is not efficient for multiple rows so used batch instead