The project uses the MyBatis to do the persistence layer, the database is Oracle, uses the batch insert function, because previously did is the MySQL, also did postgresql the database, the batch inserts the statement to be identical, but was not good in Oracle. Later on the Internet search, the general writing there are two kinds:
<insert id= "Batchinsert" parametertype= "Java.util.List" usegeneratedkeys= "false" >
INSERT INTO User_care_ SITE (user_id, care_site_id)
<foreach collection= "list" item= "item" index= "index" separator= "union All" >
(select #{item.userid,jdbctype=integer}, #{item.caresiteid,jdbctype=integer} from dual)
</foreach>
</insert>
<insert id= "Batchinsert" parametertype= "java.util.List" >
Insert all
<foreach collection= "List" Item= "Item" > Into
user_care_site (user_id, care_site_id)
VALUES (#{item.userid,jdbctype=integer}, #{ Item.caresiteid,jdbctype=integer})
</foreach>
SELECT * from DUAL
</insert>
But my side of the console always reported that the Ora-00933:sql command did not end correctly, and then I will directly copy the statement to the sqldeveloper inside the execution, can work. Then compared to their own code and the user's code, almost the same ah, but MyBatis always pass, so I guess this may be mybatis inside the error.
Then Google to the Netizen mybatis BULK INSERT data to Oracle, which mentioned the "reason is MyBatis BULK insert Oracle need to explicitly specify as usegeneratedkeys=" false or Error ~ ~ ~ ". Test, sure enough, but other users can not set this property can work, because they mybatis in the configuration file (mine is mybatis-config.xml) or not set this attribute value, because the default is False, or the value is set to False, and I have to set it to true, sad ....
<!--allows JDBC to support generated keys. Need to fit the driver. If set to true this setting forces the generated keys to be used, although some drivers are rejected compatible but still valid (such as Derby), the default false-->
<setting name= "Usegeneratedkeys" value= False "/>
I don't know which features will be affected after this property is set to False, which I haven't met yet. This is written to facilitate everyone in the search for a problem when one more source of answers.