When criteria is declared that references another entity (requires table join), generated SQL statement uses a random alias for the joined table: occasionally, the random string begins with an integer, and this is problematic for certain databases/versions.
For example, the following generated query statement (trimmed):
Complains about "Syntax error at or near '.'"
Next invocation of criteria succeeds because generated alias is different (begins with alpha char). This causes intermittent errors on some platforms/stacks, which are difficult to diagnose.
Note: this particular error was encountered with Grails (GORM), Hibernate4 plugin + postgres, using grails criteria builder + aliases.
Hibernate: 5.0.1, postgres: 5.0.1, grails 3.1.0, plugin:org.grails.plugins:hibernate4:5.0.1