Return all generated keys for inserts
See original GitHub issueIf multiple values are inserted with Statement.RETURN_GENERATED_KEYS
set, driver returns only the last generated key/identity value on calling getGeneratedKeys
. But according to JDBC spec,
The ResultSet object returned by getGeneratedKeys will contain a row for each value that a statement generated.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:14
- Comments:19 (8 by maintainers)
Top Results From Across the Web
Retrieving auto-generated keys for an INSERT statement - IBM
To retrieve automatically generated keys that are generated by an INSERT statement, you need to perform these steps: Use one of the following...
Read more >Returning the Generated Keys in JDBC - Baeldung
Learn how to return auto-generated keys with only the JDBC. ... String QUERY = "insert into persons (name) values (?)" ...
Read more >JDBC How to get all generated keys from single insert with ...
For SQL Server 2008 and later, adding an OUTPUT clause to the INSERT statement seems to do the trick: try (Statement st =...
Read more >Autogenerated keys
JDBC's auto-generated keys feature provides a way to retrieve values from columns that are part of an index or have a default value...
Read more >How to get primary key value (auto-generated keys) from ...
If you insert records into a table which contains auto-incremented column, using a Statement or, PreparedStatement objects. You can retrieve ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is a limitation from SQL Server’s end and there’s not much the driver can do. After speaking with the SQL Server team, changing the server response to return all generated keys instead of the last one (similar to OracleDB for example) would not be a trivial task, and the change likely won’t be made as it will break a lot of existing design. However, we’re keeping this issue open for future references.
@stolsvik please re-read comment above that this is a SQL Server limitation. This issue is left open for tracking purposes only the driver team is not going to be implementing any hacks to workaround. This is filed in our backlog we will look into supporting when SQL Server addresses the limitation.