I tried the same job with iBatis and it works! It seems that the problem is myBatis, or simply my ItemWriter implementation.
I'm new to ibatis/mybatis, so I defined my own MyBatisBatchItemWriter starting from the "official" IbatisBatchItemWriter; but in MyBatis the SqlMapClientCallback/SqlMapExecutor classes are absent.
This is an excerpt of IbatisBatchItemWriter#write method:
Code:
List<BatchResult> results = (List<BatchResult>) sqlMapClientTemplate.execute(
new SqlMapClientCallback() {
public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
executor.startBatch();
for (T item : items) {
executor.update(statementId, item);
}
try {
return executor.executeBatchDetailed();
} catch (BatchException e) {
throw e.getBatchUpdateException();
}
}
});
And this is what I wrote for myBatis:
Code:
public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {
if (sqlSession == null) {
this.sqlSession = new SqlSessionTemplate(sqlSessionFactory, ExecutorType.BATCH);
}
}
public void write(final List<? extends T> items) {
...
for (T item : items) {
sqlSession.update(statementId, item);
}
...
}
Clearly, my implementation is not correct...
How can I rewrite the method? Or, has anyone ever used myBatis in a Spring Batch project? Are myBatis reader/writer planned in future releases? If no, why?
Thanks,
alby