Autoincrement primary key column in H2 causes allocation of new value
during execution of INSERT. Normally these values should be returned from
Statement.getGeneratedKeys(). Somehow this API works fine with H2.196. In
latest code some major refactoring was done using new class in H2 -
GeneratedKeys. Now there is a possibility that generated keys collected
in GeneratedKeys data structure that is held by Session during INSERT
execution are GONE, if during INSERT there is a trigger that does another
INSERT...
public void setCurrentCommand(Command command, Object
generatedKeysRequest) {
this.currentCommand = command;
// Preserve generated keys in case of a new query due to possible
nested
// queries in update
if (command != null && !command.isQuery()) {
getGeneratedKeys().clear(generatedKeysRequest);
}
This occurs inside of Session.setCurrentCommand...
I suppose this
// Preserve generated keys in case of a new query due to possible
nested
// queries in update
is TODO?
I see that it could be solved by moving responsibility to maintain
GeneratedKeys
data structure directly to Command/CommandContainer objects.. So, then
nesting of queries (in a form of stack) won't clear this state in "shared"
Session.
Each command (like INSERT) then is able to return its generated keys
properly.
--
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 view this discussion on the web visit
https://groups.google.com/d/msgid/h2-database/6fceb305-8c11-47a4-bea5-2baac3d8d0f2%40googlegroups.com.