|
I found this on PostgreSQL, but I believe it might be the same on other databases, since there's nothing inherently PostgreSQL-specific at play. Anyway, IdentityGenerator is supposed to be supported on PostgreSQL per
HB-875
.
When one uses quoted identifiers - I mean explicitly quoted column names, not globally_quoted_identifiers, e.g. @Column(name = "`id`") - there's an inconsistency in IdentityGenerator: since it gets column names from the EntityPersister, in particular persister.getRootTableKeyColumnNames(), it always sees quoted identifiers; in the example above, on PostgreSQL it would always get the Java string "\"id\"" as the column name. That's all fine and good until those quoted names are used to extract the generated values from the ResultSet obtained by getGeneratedKeys() - the call to IdentifierGeneratorHelper.getGeneratedIdentity at line 100 in version 4.3.5. At least on Postgres, that ResultSet reports non-quoted column names, so calling resultSet.get("\"id\"") will not return the value of the id column!
We always quote all identifiers because our product builds Hibernate mappings live from an existing database and it has to work consistently with case-sensitive databases, reserved words etc.
I worked around it with a hack - strip quotation characters from the column name if present - but ideally the column name should only be quoted when needed. See the attached file for my hackish solution.
|