[ http://issues.apache.org/jira/browse/IBATIS-261?page=all ]
     
Sven Boden closed IBATIS-261:
-----------------------------

    Fix Version: 2.2.0
     Resolution: Invalid
      Assign To: Sven Boden

This is not a bug in iBATIS, so I'm closing the JIRA. I would suggest to use 
the dev mailing list for further discussion... if required.

I made small testcase with Oracle to simulate the problem, the easiest for you 
would be to put a breakpoint on the method executeBatch() in SqlExecutor and 
step through that method (and also going into batch.executeBatch()).
What you will detect in there is that the updates/inserts get executed properly 
but the return array of ints of executeBatch will contain all -2's, which get 
translated to 0 and added up... so you will always get 0 back upon successful 
execution.

The reason is Oracle (not the JDBC drivers, Oracle). From the Oracle manuals: 
"For a prepared statement batch, it is not possible to know the number of rows 
affected in the database by each individual statement in the batch. Therefore, 
all array elements have a value of -2. According to the JDBC 2.0 specification, 
a value of -2 indicates that the operation was successful but the number of 
rows affected is unknown.", hence your problem with the row count.

Oracle has decided not to support the row count in a batch for 
PreparedStatements. iBATIS uses PreparedStatements, even if you use all $$ 
notation (PreparedStatement without parameters) and that's why you get a 0 row 
count. The JDBC spec leaves it open, Oracle took the easy way out in this case, 
HSQL implemented it.

Just on a side note:
- Oracle also does not support batch processing for non-PreparedStatements (you 
can put them in a batch, but they are sent 1 by 1 to the database server 
without batching).
- You do need PreparedStatements with properly binded arguments for Oracle 
unless you want to experience severe performance and scalability problems.

Sven



> CLONE -The method executor.executeBatch() always returns 0.
> -----------------------------------------------------------
>
>          Key: IBATIS-261
>          URL: http://issues.apache.org/jira/browse/IBATIS-261
>      Project: iBatis for Java
>         Type: Bug
>   Components: SQL Maps
>     Versions: 2.1.0
>  Environment: SUN JVM 1.4.2 On Windows
>     Reporter: Arne Burmeister
>     Assignee: Sven Boden
>      Fix For: 2.2.0

>
> I am using Sql Maps 2.1.5 with Spring 1.2.4.
> I have a method as following. 
> I want to get the number of rows updated in the batch . 
> But it always returns 0. 
> public int insertBatchError(final List batchErrorList) { 
>         Integer count = (Integer) getSqlMapClientTemplate().execute(new 
> SqlMapClientCallback() { 
>             public Object doInSqlMapClient(SqlMapExecutor executor) throws 
> SQLException { 
>              executor.startBatch(); 
>                 for (int i = 0; i < batchErrorList.size(); i++) { 
>                  BatchErrorDTO batchErrorDto = (BatchErrorDTO) 
> batchErrorList.get(i); 
>                     executor.update("insertBatchError", batchErrorDto); 
>                 } 
>                 int count = executor.executeBatch(); 
>                 return new Integer(count); 
>             } 
>         }); 
>          
>         return count.intValue(); 
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira

Reply via email to