IT序号网

hibernate之Grails的MySQL错误

zhwl 2026年07月28日 编程语言 137 0

当添加新的实体订单并运行应用程序时,我在cmd中收到此MYSQL错误消息,谁能告诉我为什么会收到这样的错误。

| Error 2012-04-21 00:03:28,002 [Thread-7] ERROR hbm2ddl.SchemaUpdate  - Unsucce 
ssful: create table order (id bigint not null auto_increment, version bigint not 
 null, customer_id bigint not null, item_id bigint not null, notes varchar(255) 
not null, order_date datetime not null, order_price varchar(255) not null, qty v 
archar(255) not null, taken_by varchar(255) not null, primary key (id)) ENGINE=I 
nnoDB 
| Error 2012-04-21 00:03:28,006 [Thread-7] ERROR hbm2ddl.SchemaUpdate  - You hav 
e an error in your SQL syntax; check the manual that corresponds to your MySQL s 
erver version for the right syntax to use near 'order (id bigint not null auto_i 
ncrement, version bigint not null, customer_id b' at line 1 
| Error 2012-04-21 00:03:28,008 [Thread-7] ERROR hbm2ddl.SchemaUpdate  - Unsucce 
ssful: alter table item add index FK317B13A35B400E (order_id), add constraint FK 
317B13A35B400E foreign key (order_id) references order (id) 
| Error 2012-04-21 00:03:28,009 [Thread-7] ERROR hbm2ddl.SchemaUpdate  - You hav 
e an error in your SQL syntax; check the manual that corresponds to your MySQL s 
erver version for the right syntax to use near 'order (id)' at line 1 
| Error 2012-04-21 00:03:28,011 [Thread-7] ERROR hbm2ddl.SchemaUpdate  - Unsucce 
ssful: alter table order add index FK651874E47370946 (item_id), add constraint F 
K651874E47370946 foreign key (item_id) references item (id) 
| Error 2012-04-21 00:03:28,013 [Thread-7] ERROR hbm2ddl.SchemaUpdate  - You hav 
e an error in your SQL syntax; check the manual that corresponds to your MySQL s 
erver version for the right syntax to use near 'order add index FK651874E4737094 
6 (item_id), add constraint FK651874E47370946 fo' at line 1 
| Error 2012-04-21 00:03:28,016 [Thread-7] ERROR hbm2ddl.SchemaUpdate  - Unsucce 
ssful: alter table order add index FK651874EF3CCBB66 (customer_id), add constrai 
nt FK651874EF3CCBB66 foreign key (customer_id) references customer (id) 
| Error 2012-04-21 00:03:28,019 [Thread-7] ERROR hbm2ddl.SchemaUpdate  - You hav 
e an error in your SQL syntax; check the manual that corresponds to your MySQL s 
erver version for the right syntax to use near 'order add index FK6 
 
51874EF3CCBB6 
6 (customer_id), add constraint FK651874EF3CCBB6' at line 1 

请您参考如下方法:

您无法命名表order,因为它是SQL语法中的保留字:http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html。但是,您可以使用映射将表名更改为订单:

class Order { 
    static mapping = { 
        table "orders" 
    } 
} 


评论关闭
IT序号网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!