mybatis oracle batch update using foreach

3,397 views
Skip to first unread message

sandeep reddy

unread,
Sep 10, 2014, 8:08:58 AM9/10/14
to mybati...@googlegroups.com

I'm trying to insert a list of records to an Oracle 11g table. I tried the MyBatis syntax with foreach but it fails with ORA-00933: SQL command not properly ended exception when the list has more than one record.

The generated sql in this case looks like:

UPDATE CUSTOMER_T SET app_name = ?, start_date = ?, end_date = ? WHERE customer_id=?

UPDATE CUSTOMER_T SET app_name = ?, start_date = ?, end_date = ? WHERE customer_id=?

Below is my the query in the mapper:

<update id="updateApplication" parameterType="com.test.mybatis.Application">

        <foreach item="ca" collection="customer.applications.applcation"
            open="" close="" separator="">
        UPDATE CUSTOMER_T
        SET app_name = #{ca.appName,jdbcType=VARCHAR},      
        start_date = #{ca.startDate,jdbcType=DATE,javaType=javax.xml.datatype.XMLGregorianCalendar},
        end_date = #{ca.endDate,jdbcType=DATE,javaType=javax.xml.datatype.XMLGregorianCalendar}
        WHERE
        customer_id=#{customer.info.customerid}
        </foreach>      
    </update>   

I appreciate if someone could identify the issue here. Specifically how to get this to work with Oracle?

Jeff Butler

unread,
Sep 10, 2014, 9:29:11 AM9/10/14
to mybati...@googlegroups.com
We generally do not recommend this approach.  It's better to write a single update statement and make the loop in Java.  If you are concerned about performance, then you can use the batch executor.  This is not a batch, it is just one giant statement.

Jeff Butler

--
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 mybatis-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages