Why does BatchExecutor only remember one sql/statement

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Why does BatchExecutor only remember one sql/statement

Daniel Guggi
hi,

we ran into a max open cursor problem on oracle when doing batch inserts (using two different statements) within one sqlsession/transaction.

the code did something like this:

for (int i=0; i < large-nuber; i++) {
   batchMapper1.doInsert();
   batchMapper2.doAnotherInsert();
}


it turned out that the problem is related with the BatchExecutor as it only remembers "currentSql" and "currentStatement":

if (sql.equals(currentSql) && ms.equals(currentStatement)) { 
  // use existing statement
} else {
  // create new statement
}


according to this two "new" statement were created per loop, because the currentSql/currentStatement did always change -> which lead to the to many open cursor error...


we got arround this using two loops:
for (int i=0; i < large-nuber; i++) {
   batchMapper1.doInsert();
}
for (int i=0; i < large-nuber; i++) {
   batchMapper2.doAnotherInsert();
}


however I dont see why the BatchExecutor cannot remember more than on sql statement -> imo it could just have List<String> currentSqls and List<Statement> currentStatements.

What do you think - do I miss something here?

BTW. we are currently using mybatis 3.1.1

ty,
daniel

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Why does BatchExecutor only remember one sql/statement

Clinton Begin
Administrator
It's a limitation of many (if not most) JDBC drivers.  I can't recall if Oracle is one of them or not, but this is code that must be compatible with all drivers. The best solution is to try to order your writes such that statements that are the same are batched together.  

Cheers,
Clinton


On Thu, May 16, 2013 at 4:50 AM, dguggi <[hidden email]> wrote:
hi,

we ran into a max open cursor problem on oracle when doing batch inserts (using two different statements) within one sqlsession/transaction.

the code did something like this:

for (int i=0; i < large-nuber; i++) {
   batchMapper1.doInsert();
   batchMapper2.doAnotherInsert();
}


it turned out that the problem is related with the BatchExecutor as it only remembers "currentSql" and "currentStatement":

if (sql.equals(currentSql) && ms.equals(currentStatement)) { 
  // use existing statement
} else {
  // create new statement
}


according to this two "new" statement were created per loop, because the currentSql/currentStatement did always change -> which lead to the to many open cursor error...


we got arround this using two loops:
for (int i=0; i < large-nuber; i++) {
   batchMapper1.doInsert();
}
for (int i=0; i < large-nuber; i++) {
   batchMapper2.doAnotherInsert();
}


however I dont see why the BatchExecutor cannot remember more than on sql statement -> imo it could just have List<String> currentSqls and List<Statement> currentStatements.

What do you think - do I miss something here?

BTW. we are currently using mybatis 3.1.1

ty,
daniel

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
 
 

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Loading...