Duplicate
Details
Details
Assignee
Unassigned
UnassignedReporter
Shaun Wilde
Shaun WildeLabels
Components
Affects versions
Priority
Who's Looking?
Open Who's Looking?
Created May 19, 2010 at 7:23 PM
Updated November 20, 2016 at 1:18 PM
Resolved November 22, 2014 at 3:47 PM
This issue is if you are using the PostgreSQL81Dialect or PostgreSQL82Dialect dialects.
The PostgreSQL81Dialect uses ';select lastval()' (see AppendIdentitySelectToInsert) to get the last identifier generated by nextval however this is not scoped so if your insert causes a trigger to fire which also calls nextval on a different sequence (say if you were inserting data into another table) then select lastval() will return the wrong value.
The base class PostgreSQLDialect uses 'returning ?' (see AddIdentifierOutParameterToInsert) which is the recommended way to get the identifer from your insert operation.
If you extend Postgres82SQLDialect to correct the issue, but to keep the extra capabilities, you hit an issue that AddIdentifierOutParameterToInsert is not called and AppendIdentitySelectToInsert is called instead; the former method has the name of the identity column that you would have to use but AppendIdentitySelectToInsert does not and thus you have to hardcode the column name in the string (okay if all your identity columns are the same name).
It also seems odd to have 2 overrides that appear to do the same thing - but that I suppose is a different issue.