<insert id="insert" parameterType="ComponentGroups">
   insert into component_groups
   (group_id,package_name,class_name) values (#{group_id},#{package_name},#{class_name})
   <selectKey resultType="java.math.BigDecimal" keyProperty="component_groups_id">
    select COMPONENT_GROUPS_ID.currval from dual
   </selectKey>
</insert>

只有这样做才能在输入的ComponentGroups中设置新插入的ID,并且保证ID的增长是+1,而不是加2.其中COMPONENT_GROUPS_ID是component_groups这张表的主键自增序列。

-------------------------------------------

从网上查阅相关资料,整理了一个Oracle批量插入的方法:

 




1. <insert id="insertBatch" parameterType="ArrayList" useGeneratedKeys="true">  
2. "deptno" order="BEFORE" resultType="int">  
3.             SELECT S_FORUM_USERID.NEXTVAL FROM DUAL  
4.         </selectKey>  
5.           
6.         INSERT INTO DEPT(DEPTNO , DNAME , LOC) SELECT S_FORUM_USERID.NEXTVAL , A.* FROM (  
7. "list" item="item" index="index" separator="UNION">  
8.             SELECT #{item.dname} , #{item.loc} FROM DUAL  
9.         </foreach>  
10.         ) A  
11.     </insert>