I found the reason for this, after reading various resources and trial and error, I wrote down our results here, as this may help someone else.
It turns out that different types of behavior were associated with our DAO classes extending Spring SqlMapClientTemplate. In this class, you have two "choices" (I say the choice, one is correct, in fact it is not):
direct use of insert (), update (), etc .; using full Spring objects completely
getSqlMapClient (). insert (), update (), etc .; this one actually works using the com.ibatis ... object returned by getSqlMapClient (), not Spring one
Both generally work, but from my reading the first option is better, for example. if you use Spring, you want to be completely Spring, and not "jump" onto Ibatis objects.
Now SqlMapClientTemplate does not provide access to startBatch () / executeBatch () directly, just a convenient insert (), update (), so this code is necessary to do this. The code below works fully with our Spring-driven transactions, not the explicit startTransaction () code in sight.
(a disclaimer may contain errors due to my "anonymous" working code for clarity)
public class MyFunkyDao extends SqlMapClientDaoSupport { private static final int DB_BATCH_SIZE = 1000; public void storeMyData(final List<MyData> listData) { getSqlMapClientTemplate().execute( new SqlMapClientCallback() { @Override public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException { int count = 0, total = 0; Map<String, Object> params = new HashMap<String, Object>(); executor.startBatch(); for (MyData data: listData) { params.put("param name 1", data.getValue()); executor.insert("insertData", params); count++; if (count % DB_BATCH_SIZE == 0) { total += executor.executeBatch(); executor.startBatch(); } params.clear(); } total += executor.executeBatch(); return new Integer(total); } }); } }
Link: http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/orm/ibatis/SqlMapClientTemplate.html
Brian source share