1

I am trying to make a simple web app for a school project in Grails. I can access the server, save, delete, and everything else, but whenever I first run the app I am getting masses of SQL errors thrown at me. I am using Grails 2.0.3 and mysql-connector-java-5.1.19.

I get the following error and many others like it:

Error 2012-04-25 14:28:54,009 [pool-5-thread-1] ERROR hbm2ddl.SchemaUpdate - Unsuccessful: alter table character_trait add index FK93D74D785F2F8048 (character_traits_id), add constraint FK93D74D785F2F8048 foreign key (character_traits_id) references character (id)

Error 2012-04-25 14:28:54,009 [pool-5-thread-1] ERROR hbm2ddl.SchemaUpdate - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'character (id)' at line 1

And when querying using the findby dynamic finders:

Class com.mysql.jdbc.exceptions.MySQLSyntaxErrorException

Message You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'character this_ where this_.player_id=1 limit 1' at line 1

Any ideas on why this is happening?

Howes
  • 799
  • 1
  • 7
  • 15

1 Answers1

1

CHARACTER is a reserved word in MySQL. It needs to be quoted to be used as a table or column name. You can quote it in the table mapping like so:

class Character {
    static mapping = {
        table name: '`character`'
    }
}
ataylor
  • 64,891
  • 24
  • 161
  • 189
  • @ataylor..same thing is happening with me for column name `to`, please tell me how I need to declare this in static mapping, I did as follows: `static mapping = { to name:'`to`' }` but did not work for me. Please tell me correct way for solve this problem for column name. – mark Apr 09 '14 at 10:54
  • @ataylor..I have solved that problem, bu using `static mapping = { to column: '`to`' }` thanks for your answer, it helped me a lot. – mark Apr 09 '14 at 11:03