-
Notifications
You must be signed in to change notification settings - Fork 38.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Batch update return generated keys #28132
Batch update return generated keys #28132
Conversation
…der. This batch update uses the form of JdbcTemplate#batchUpdate that takes PreparedStatementCreator with the flag set to return generated keys.
…der and keyColumnNames.
I'm getting some checkstyle violations trying to build. Could you fix them so I can try this out? Thanks. |
… batch operations.
This is to avoid frequent resizing of the row mapper ArrayList when extracted keys for a batch operation.
@trisberg I resolved the checkstyle violations and made some other updates. |
Any update on this topic? Is it abandoned or is something still to be considered? |
Would be nice to have this merged already. |
} | ||
} | ||
|
||
private PreparedStatementCallback<int[]> getPreparedStatementCallback(BatchPreparedStatementSetter pss, @Nullable KeyHolder generatedKeyHolder) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest a more descriptive name:
private PreparedStatementCallback<int[]> getPreparedStatementCallback(BatchPreparedStatementSetter pss, @Nullable KeyHolder generatedKeyHolder) { | |
private PreparedStatementCallback<int[]> getPreparedStatementCallbackForBatchUpdate(BatchPreparedStatementSetter pss, @Nullable KeyHolder generatedKeyHolder) { |
(Of course, also adjust this where it's used.)
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. |
@snicoll not sure what kind of thoughts you are looking for. The changes in Spring Data JDBC are creating a copy of frameworks |
@ctailor2 and all, thanks for your patience and please use |
BatchJdbcOperations is still there, but deprecated, and not used except for deprecated places kept for backward compatibility. This is possible since Spring Framework made the features offered by `BatchJdbcOperations` part of `NamedParameterJdbcOperations`. See spring-projects/spring-framework#28132 See #1191
Add
NamedParameterJdbcTemplate#batchUpdate
methods takingKeyHolder
andString[] keyColumnNames
as counterparts to theNamedParameterJdbcTemplate#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 tospring-data-jdbc
currently include a copy of the changes being proposed here, and could be refactored to use the respectiveNamedParameterJdbcTemplate#batchUpdate
once accepted and merged.Related to #6530.