Insert a list of objects using MyBatis 3
        Posted  
        
            by 
                T Soares
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by T Soares
        
        
        
        Published on 2012-01-09T14:18:25Z
        Indexed on 
            2012/09/23
            21:38 UTC
        
        
        Read the original article
        Hit count: 447
        
I've tried to insert a list in a database but I've got some the error: org.springframework.jdbc.BadSqlGrammarException: SqlSession operation; bad SQL grammar []; nested exception is java.sql.SQLException: ORA-00913: too many values (...).
The code that I've used:
<insert id="insertListMyObject" parameterType="java.util.List" >
INSERT INTO my_table
   (ID_ITEM,
    ATT1,
    ATT2)
    VALUES
   <foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
    #{item.idItem, jdbcType=BIGINT},
    #{item.att1, jdbcType=INTEGER},
    #{item.att2, jdbcType=STRING}
       </foreach>   
</insert>
My dao cals the method:
SqlSessionTemplate().insert(MAPPER+".insertListMyObject", parameterList);
Where the parameterList is:
List<MyObjects>.
Does someone have a clue about what's this error? Or if does exists a better way to do multiples inserts operation.
Many thanks!
© Stack Overflow or respective owner