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?
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`'
}
}