Batch operations for @Query
I would like to create such an usage but it seems it is not supported yet. I can also contribute for batch query operations.
@Modifying
@Query("UPDATE DUMMYENTITY SET name = :name WHERE id = :id")
int[] updateName(List<User> users);
I tried to check it is already supported or not but could not find anything.
How do you intend this to work? Where is the name to come from? How would the return value be determined? Are JDBC drivers even able to batch such statements?
Return value is limited with int[] or boolean[]. I was actually considering to use Spring JDBC Batch operations as Spring Documentation:
public class JdbcActorDao implements ActorDao {
private SimpleJdbcTemplate simpleJdbcTemplate;
public void setDataSource(DataSource dataSource) {
this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
}
public int[] batchUpdate(final List<Actor> actors) {
SqlParameterSource[] batch = SqlParameterSourceUtils.createBatch(actors.toArray());
int[] updateCounts = simpleJdbcTemplate.batchUpdate(
"update t_actor set first_name = :firstName, last_name = :lastName where id = :id",
batch);
return updateCounts;
}
// ... additional methods
}
Each bean is expanded and filled into query.
Any advice about it? If you can guide me regarding changes, I can submit a PR too.
Will be no comments about this?
How do you expect this project to be developed without paying attention to its community? Seriously?
There are dozens issues without any comment, PRs outstanding since 2019.
I am offering help since we are using this project and feeling responsible to improve it but I see just inattention from the project staff.
I think this is a valid enhancement.
If anyone wants to contribute StringBasedJdbcQuery would be the place to start.