ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephen Boyd" <swb...@gmail.com>
Subject Re: Spring DAO executeBatch() returns 0 ??
Date Fri, 11 Jan 2008 14:41:41 GMT
What version of Spring are you using?  I *think* they fixed it in 2.0.5.

On Jan 9, 2008 6:15 PM, Warren <warren@clarksnutrition.com> wrote:

> I just got done switching the Ibatis DAO to Spring DAO per the
> instructions
> written by Larry. Everything is working fine except whenever I use
> SqlMapClient  executeBatch(). It always returns 0 even though all the
> records were inserted. I have a method in my DAO that inserts a List of
> records within a batch. executeBatch() use to return the number of records
> inserted when I was useing the Ibatis DAO, now it returns 0 when using the
> Spring DAO.
>
> Also, am I even doing this correctly, is there a better way? I see a
> comment
> in the Spring SqlMapClientTemplate that talks about an anonymous inner
> class:
>
>  * for more complex
>  * operations like batch updates, a custom SqlMapClientCallback must be
> implemented,
>  * usually as anonymous inner class. For example:
>  *
>  * getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
>  *       public Object doInSqlMapClient(SqlMapExecutor executor) throws
> SQLException {
>  *               executor.startBatch();
>  *               executor.update("insertSomething", "myParamValue");
>  *               executor.update("insertSomethingElse",
> "myOtherParamValue");
>  *               executor.executeBatch();
>  *               return null;
>  *       }
>  * });
>
> I am not quite sure how to implement this in my DAO code. Anyway, here is
> my
> current code:
>
>
> IBATIS DAO that extends com.ibatis.dao.client.template.SqlMapDaoTemplate
>
> ...
>    SqlMapExecutor sqlMap = getSqlMapExecutor();
> ...
>        sqlMap.startBatch();
>        ListIterator listIterator = parameterList.listIterator();
>        while(listIterator.hasNext())
>        {
>                insert(statementName, listIterator.next());
>        }
>        numberOfRecords = sqlMap.executeBatch();
> ...
>
>
> SPRING DAO that extends
> org.springframework.orm.ibatis.SqlMapClientTemplate
>
> ...
>    SqlMapClient sqlMap = getSqlMapClient();
> ...
>        sqlMap.startBatch();
>        ListIterator listIterator = parameterList.listIterator();
>        while(listIterator.hasNext())
>        {
>                insert(statementName, listIterator.next());
>        }
>        numberOfRecords = sqlMap.executeBatch();
> ...
>
> Thanks,
>
> Warren
>
>

Mime
View raw message