You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ibatis.apache.org by "Arne Burmeister (JIRA)" <ib...@incubator.apache.org> on 2006/02/17 18:03:24 UTC

[jira] Created: (IBATIS-261) CLONE -The method executor.executeBatch() always returns 0.

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


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


[jira] Closed: (IBATIS-261) CLONE -The method executor.executeBatch() always returns 0.

Posted by "Sven Boden (JIRA)" <ib...@incubator.apache.org>.
     [ 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


[jira] Commented: (IBATIS-261) CLONE -The method executor.executeBatch() always returns 0.

Posted by "Arne Burmeister (JIRA)" <ib...@incubator.apache.org>.
    [ http://issues.apache.org/jira/browse/IBATIS-261?page=comments#action_12367022 ] 

Arne Burmeister commented on IBATIS-261:
----------------------------------------

Neither Oracle 9 or 10 Driver worked - the current setup is client/server Oracle 10:

Database: jdbc:oracle:thin:@<server>1521:<db> (Oracle Oracle Database 10g Release 10.1.0.3.0 - Production)
Driver: Oracle JDBC driver 10.2.0.1.0

> 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

>
> 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


[jira] Commented: (IBATIS-261) CLONE -The method executor.executeBatch() always returns 0.

Posted by "Sven Boden (JIRA)" <ib...@incubator.apache.org>.
    [ http://issues.apache.org/jira/browse/IBATIS-261?page=comments#action_12367105 ] 

Sven Boden commented on IBATIS-261:
-----------------------------------

Can you also attach the SqlMaps you use (e.g. from the insertBatchError). From experience I know that Oracle places some very heavy restrictions on the return code of an update in a batch. You will very likely hit the restrictions: PreparedStatements, PL-SQL, ...  If this is the case it's not an iBATIS but an Oracle problem.

Attach the SqlMaps and I will search a bit in the Oracle documentation.



> 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

>
> 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


[jira] Commented: (IBATIS-261) CLONE -The method executor.executeBatch() always returns 0.

Posted by "Arne Burmeister (JIRA)" <ib...@incubator.apache.org>.
    [ http://issues.apache.org/jira/browse/IBATIS-261?page=comments#action_12367161 ] 

Arne Burmeister commented on IBATIS-261:
----------------------------------------

The update SqlMap is very simple, the problem also occurs on insert - seems to be a general Problem

    <update id="updateItemPosition" parameterClass="com.x.Item">
        update item
        set
            pos = #position:NUMERIC#
        where
            id = #id:NUMERIC#
    </update>

The wrapping Spring-Code is as follows:

			com.ibatis.sqlmap.client.SqlMapSession session = this.sqlMapClient.openSession();

			try {

				java.sql.Connection con = DataSourceUtils.getConnection(getDataSource());

				try {

					session.setUserConnection(con);

					return action.doInSqlMapClient(session);

				}

				catch (SQLException ex) {

					throw getExceptionTranslator().translate("SqlMapClient operation", null, ex);

				}

				finally {

					DataSourceUtils.releaseConnection(con, getDataSource());

				}

			}

			finally {

				session.close();

			}



> 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

>
> 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


[jira] Commented: (IBATIS-261) CLONE -The method executor.executeBatch() always returns 0.

Posted by "Arne Burmeister (JIRA)" <ib...@incubator.apache.org>.
    [ http://issues.apache.org/jira/browse/IBATIS-261?page=comments#action_12366814 ] 

Arne Burmeister commented on IBATIS-261:
----------------------------------------

I just got the same with 2.1.6!

The bug seems to depend on the JDBC-Driver!
No Problem with HSQL, but every time with Oracle Thin Driver...

We also use Spring (2.0) and Java 1.5 - the code looks like:

? extends org.springframework.orm.ibatis.support.SqlMapClientDaoSupport
{

    protected void update(final String updateName, final Collection< ? > parameterObjects)
    {
        debug(updateName, parameterObjects);
        SqlMapClientTemplate sqlTemplate = getSqlMapClientTemplate();
        Integer result = (Integer)sqlTemplate.execute(new SqlMapClientCallback() {
            public Object doInSqlMapClient(SqlMapExecutor executor)
                    throws SQLException
            {
                executor.startBatch();
                for (Object parameterObject : parameterObjects) {
                    executor.update(updateName, parameterObject);
                }
                return new Integer(executor.executeBatch());
            }
        });
        if (result.intValue() != parameterObjects.size()) {
            throw new JdbcUpdateAffectedIncorrectNumberOfRowsException(
                    updateName, parameterObjects.size(), result.intValue());
        }
    }

}

We always get the JdbcUpdateAffectedIncorrectNumberOfRowsException

> 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

>
> 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