question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make @SqlUpdate able to return the generated keys

See original GitHub issue

As I checked, the Update does have a method executeAndReturnGeneratedKeys to return the insert statement’s generated keys. But when I use the SqlObject api @SqlUpdate, it only returns the updated rows count. What about to add a property in @SqlUpdate to tell the UpdateHandler to return the generated keys?

Issue Analytics

  • State:closed
  • Created 11 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
stevenschlanskercommented, Sep 5, 2014

At least in Postgres, you can e.g. INSERT ... RETURNING * and then use @SqlQuery instead and it should work. Not sure about other databases.

1reaction
oludouglascommented, May 18, 2017

From the little research I’ve done online, you can just annotate the method like this. @SqlUpdate(“insert into user(username) values (‘douglas’)”) @GetGeneratedKeys public long createUser();

and then get the long returned from the DAO

Read more comments on GitHub >

github_iconTop Results From Across the Web

Returning the Generated Keys in JDBC - Baeldung
Learn how to return auto-generated keys with only the JDBC. ... In order to be able to execute SQL queries, we're going to...
Read more >
BatchSqlUpdate - how to get auto generated keys
How do I get the auto generated keys for all of the rows inserted? When doing a single insert I get the keys...
Read more >
Retrieving auto-generated keys for an INSERT statement - IBM
Use one of the following methods to indicate that you want to return automatically generated keys: If you plan to use the PreparedStatement.executeUpdate...
Read more >
Batch inserts with auto incremented keys - Google Groups
JDBI says that batch methods must either return void or int[] array with the ... Yes, I know I can do single insert...
Read more >
Documentation: 15: UPDATE - PostgreSQL
The optional RETURNING clause causes UPDATE to compute and return value(s) ... Do not include the table's name in the specification of a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found