Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • If MySQL JDBC driver implements it. Commented Nov 9, 2009 at 8:53
  • That's true. If the JDBC driver doesn't support it, you need to rely on database specific methods to get the ID. Commented Nov 9, 2009 at 9:07
  • @kgiannakakis - session.save(myTable) doesn't return an int. It however, returns java.io.serializable and the getGeneratedKeys() method is not supported by any implementation of the JDBC drivers until now. So neither of the two cases which you mentioned would be successful as obvious. Do they really work? Commented Nov 9, 2012 at 0:37
  • @Lion - Integer does implement Serializable. So using boxing you can get an int out of session.save(myTable), provided of course that the mapping of your table is such as to return an int. This method works. I have successfully tested getGeneratedKeys method with MySQL JDBC driver. Commented Nov 9, 2012 at 8:09