Search code examples
hibernateormgrailsderbyjavadb

user table with javaDB and Hibernate from within grails


let's see if I can ask this in an understandable way...

I started with grails and created a domain class called user. As far as I understand, Hibernate is used to map this domain class to the database. This works pretty fine with hsqldb.

Now I tried to switch to javaDB and get an error message because the table is called "user" (which seems to be a reserved word for javaDB).

So a statement like

create table user ...

will result in an error message.

create table "user" ...

works, but Hibernate seems not put put the table name in quotes.

How can I configure Hibernate to use quotes in order to make it work with my table name?

PS: yes, I know, I could map the domain class to another table name... :-)


Solution

  • got it. As Pascal already mentioned, the mapping entry is the key. But instead of using double quotes, a back tick will bring success:

    static mapping = {
      table "`user"
    }
    

    this tells hibernate to put the table name in quotes when generating the sql. It seems also to work with all corresponding tables... but somehow it drops the last character of "user" in some of them... :-(

    So it seems that indeed remapping the domain class to a table name which will not cause any problems will be the best way:

    static mapping = {
      table "appuser"
    }