[hibernate-dev] Auto quoting of keywords used as identifiers

Steve Ebersole steve at hibernate.org
Fri May 1 09:51:33 EDT 2015


Gail, I saw your ping on IRC and thought it made sense to address here,
since you were not around on IRC anymore.

Overall, starting with 5.0, the idea is for Hibernate to automatically
quote any identifiers is recognizes as a keyword.  This is all encapsulated
within the org.hibernate.engine.jdbc.env.spi.IdentifierHelper obtained
via org.hibernate.engine.jdbc.env.spi.JdbcEnvironment#getIdentifierHelper.

There are 2 parts to this...

First, we need to be able to recognize that an identifier is in fact a
keyword.  This piece is handled through
org.hibernate.engine.jdbc.env.spi.JdbcEnvironment#isReservedWord, which is
based on a Set of keywords computed from 2 distinct "keyword sources":
1) Dialect#getKeywords
2) DatabaseMetaData#getSQLKeywords

At the moment, I think this misses a third source... ANSI SQL 2003 standard
keywords.  DatabaseMetaData#getSQLKeywords specifically is supposed to
return only keywords beyond the standard (2003) defined ones.  There are
really 2 options to address this:
1) add these standard keywords to Dialect
2) use a seperate (static) source for them.

Personally I prefer the second.  Even if we added all the standard keywords
to the base Dialect Set, it is just too easy for the Dialect subclass to
override getKeywords().  Also, I like the idea of continuing the convention
of these other 2 sources simply returning "extras".

Second, and this is BY FAR the harder part, we need to make sure that
everywhere that is building identifiers is using this code.  I tried hard
to make sure that was the case, but we all know that annotation binding is
a mess and its just too easy to miss stuff in there.  I'm all happy for a
second (or third, or fourth, ...) pair of eyes looking over this part, but
I personally think it is not the best allocation of our time considering
the difficulty in actually finding them all just by code review and the
time it would take and the amount of other stuff we have to do.  Eventually
we will get bug reports of cases where this does not happen.  My $.02


More information about the hibernate-dev mailing list