Grails - Reserved Names

These are lists of reserved keywords for various databases that are commonly used as table or column names. When naming a domain class or a property, make sure that your target platforms do not reserve that name.

A useful web site allows to check for different databases:

http://www.petefreitag.com/tools/sql_reserved_words_checker

But you should double check with the documentation of the database you use or plan to use in the future.

MySQL

  • order
  • transaction
Reference: http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html

PostgreSQL

  • cast
  • constraint
  • user
A full list of reserved keywords for version 8.1.x can be found here.

Grails-specific reserved words

  • application - clashes with the application variable

Hibernate reserved words

See the list of keywords for HQL http://www.hibernate.org/hib_docs/reference/en/html/queryhql-expressions.html.

  • Member - used as a Grails domain class in the default package generates an Hibernate exception when used in HQL "find" or "findAll":
def r = Member.findAll("from Member")

Caused by: org.springframework.orm.hibernate3.HibernateQueryException: unexpected token: Member near line 1, column 6 from Member m; nested exception is org.hibernate.hql.ast.QuerySyntaxException: unexpected token: Member near line 1, column 6 from Member m

The fix is to move your domain classes to a package: for example "com.test.Member" (add "package com.test as the first line in Member.groovy) and the appropriate folder (com/test/Member.groovy). Make sure to add "import com.test.Member" in the controller or wherever the class is being used. then an HQL query can be written like:

def m = Member.findAll("from com.test.Member m")

or, better with this dynamic classpath query on the class name:

def m = Member.findAll("from $Member.name m")