I am using 2.5. I think I am doing it wrong to begin with. I need to study some of the Spring Docs mentioned on this mailing list.
Thanks -----Original Message----- From: Stephen Boyd [mailto:[EMAIL PROTECTED] Sent: Friday, January 11, 2008 6:42 AM To: [email protected] Subject: Re: Spring DAO executeBatch() returns 0 ?? What version of Spring are you using? I *think* they fixed it in 2.0.5. On Jan 9, 2008 6:15 PM, Warren <[EMAIL PROTECTED]> 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
