spring-framework icon indicating copy to clipboard operation
spring-framework copied to clipboard

Batch update return generated keys

Open ctailor2 opened this issue 3 years ago • 2 comments

Add NamedParameterJdbcTemplate#batchUpdate methods taking KeyHolder and String[] keyColumnNames as counterparts to the NamedParameterJdbcTemplate#update methods of the same form.

This is in service of an enhancement to spring-data-jdbc to perform batch inserts to persist collections of entities referenced by an aggregate, when adequately supported by the database. The proposed changes to spring-data-jdbc currently include a copy of the changes being proposed here, and could be refactored to use the respective NamedParameterJdbcTemplate#batchUpdate once accepted and merged.

Related to spring-projects/spring-framework#6530.

ctailor2 avatar Mar 03 '22 22:03 ctailor2

I'm getting some checkstyle violations trying to build. Could you fix them so I can try this out? Thanks.

trisberg avatar Mar 09 '22 21:03 trisberg

@trisberg I resolved the checkstyle violations and made some other updates.

ctailor2 avatar Mar 15 '22 18:03 ctailor2

Any update on this topic? Is it abandoned or is something still to be considered? Would be great to have this code merged (though I guess it needs some adjustment to the current state of the code).

pworoniecki avatar Dec 28 '22 17:12 pworoniecki

Would be nice to have this merged already.

sabomichal avatar May 04 '23 11:05 sabomichal

I just spent some hours trying to figure out how to implement this myself (or rather, how to generalize this Stack Overflow answer into something which works for my use case).

Only then I had the idea of checking whether someone already did something here, and it looks good.

ePaul avatar Aug 09 '23 21:08 ePaul

@ctailor2 thanks for the PR, it misses some tests for the changes in NamedParameterJdbcTemplate though.

@schauder can you share your thoughts? I can see something in spring data jdbc was merged with a reference to a core framework class and I am a bit puzzled by that.

snicoll avatar Aug 27 '23 15:08 snicoll

@snicoll not sure what kind of thoughts you are looking for.

The changes in Spring Data JDBC are creating a copy of frameworks NamedParameterJdbcTemplate with the changes of this PR included, because we really needed the changes. We would be glad to go back to the official NamedParameterJdbcTemplate once this PR is merged.

schauder avatar Aug 28 '23 08:08 schauder

@ctailor2 and all, thanks for your patience and please use NamedParameterJdbcTemplate proper again.

snicoll avatar Sep 15 '23 14:09 snicoll