Hibernate 6 and H2 Reserved Words

I’m working on upgrading an existing Wildfly 26 project to Wildfly 31 and as such Hibernate is going from 5.3.28 to 6.4.2

I’m running into an issue where previously using h2 for some local dev and testing worked, but now I’m getting many failures due to what appears to be sql keywords and reserved words.

I’ve confirmed that it is initializing the H2Dialect and it appears to have all the reserved word, but they don’t appear to be getting quote escaped so I’m getting failures with like a table named User where previously this was not an issue.

Anyone run into this already?

This is a known issue of H2 version 2+. You can either use the auto-quoting of Hibernate ORM or rename the tables/columns to avoid using keywords.

Perfect. I can just set auto quoting if using h2

Unfortunately there appears to be quite a bit of oddness there.

If setting hibernate.globally_quoted_identifiers then it appears to not create the table User on start (hibernate.hbm2ddl.auto) properly and I get

org.h2.jdbc.JdbcSQLSyntaxErrorException: Table \"User\" not found; SQL statement

I had to shut off the auto quoting and enable NON_KEYWORDS=USER for h2

jdbc:h2:mem:portal;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;NON_KEYWORDS=USER

Now you know why quoting is not enabled by default. Even though quoting allows to use keywords as identifiers, the problem with quoting is that it is case sensitive, so if the case for some of your used names doesn’t match, you’re going to see that problem.