google-code-export / mybatis

Automatically exported from code.google.com/p/mybatis
0 stars 0 forks source link

iBatis executeBatch not working properly when table is locked for Single Inserts #533

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What version of the MyBatis are you using?
ibatis-2.3.2.715

Please describe the problem.  Unit tests are best!
1) There is a screen in our application which inserts record in database 
through executeBatch method.
2) The batch  is used in application to insert the record instead of normal 
INSERT statement.
3) Due to some reasons  if concerned table gets locked [Table Level Lock], 
while step 1 is occuring, duplicate entries get inserted in table.
4) When Lock gets released, the table gets populated with duplicate 
entries[Only 1 Record should be inserted].
5) The number of duplicates increase as the time for which table is locked.
6) We tested it by putting LOCK manually on table and initiated the process as 
defined in step 1 above. We found duplicate entries.

What is the expected output? What do you see instead?
Only 1 record must be inserted in table. We see duplicate records.

Can you provide stack trace, logs, error messages that are displayed?
    public void batchInsertData(
            final List < ? extends XYZ> list) {
        getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
            public Object doInSqlMapClient(
                    SqlMapExecutor executor)
                    throws SQLException {
                executor.startBatch();
                for (XYZ xyz: list) {
                    executor.insert("XYZ.abatorgenerated_insert", transfer);
                }
                return executor.executeBatch();
            }
        });
    }
With the above code we are inserting only one record and we are getting the 
duplicate record issue, but if we use abover  code snippet for multiple inserts 
when table is locked, it works fine.
Please provide any additional information below.

Original issue reported on code.google.com by vishalra...@gmail.com on 1 Mar 2012 at 11:43

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I am facing the same problem and was wondering how you resolved it? Ive spend 
more than 2 developer days trying to figure it out myself. Any help would be 
appreciated

Original comment by bhavya.u...@gmail.com on 11 Sep 2013 at 5:20