MyBatis configuration for Oracle bulk inserts ____oracle

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.