Hello. JDBC specification and Javadoc from JDK require only that you can get keys from autogenerated columns when you use INSERT statement, auto-commit is disabled, batch updates are not used, keys are explicitly requested with Statement.RETURN_GENERATED_KEYS or indexes or names for the columns etc. All other ways are database-specific and should not be used in portable applications.
H2 does not require you to disable auto-commit, it supports batch updates and supports some alternative ways to insert generated keys, including some weird ones. There is some support for triggers. You can find such example with trigger and all other tests here: https://github.com/h2database/h2database/blob/master/h2/src/test/org/h2/test/jdbc/TestGetGeneratedKeys.java Code in TriggerObject that you quoted is OK, it is used to gather generated keys from normal triggers and this functionality works as expected. confirmRow() is called from Insert.insertRows(). But gathering of generated keys from views with instead of triggers is simply not supported. I think that there is no normal automatic way to implement it properly, because such triggers may do too many different and unexpected things. May be some additional API for triggers is needed to control this process manually. There is also old JDBC-incompatible way that you can enforce by appending ;SCOPE_GENERATED_KEYS=TRUE to the database connection URL. If this option is specified H2 unconditionally returns the one most recent scope identity in the current session instead of normal generated keys. It may work or may not work in your use case. -- You received this message because you are subscribed to the Google Groups "H2 Database" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/h2-database. For more options, visit https://groups.google.com/d/optout.
