hibernate生成表时候,注意不能使用mysql关键字和保留字(比如order)

问题:

今天在用hibernate建一张订单表的时候遇到了一个问题,订单的信息表始终无法创建,莫名其妙,最后发现和sql语句的关键字冲突了。现在分享一下。


报错信息如下:(指的sql语句语法错误)

01:20:45,317 ERROR SchemaUpdate:212 - Unsuccessful: create table 'order' (id integer not null auto_increment, name varchar(255), customer_id integer, primary key (id))
01:20:45,317 ERROR SchemaUpdate:213 - 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 ''order' (
id integer not null auto_increment,
name varchar(255),' at line 1
01:20:45,463 ERROR SchemaUpdate:212 - Unsuccessful: alter table 'order' add index FKD2F26980230E719A (customer_id), add constraint FKD2F26980230E719A foreign key (customer_id) references customer (id)
01:20:45,463 ERROR SchemaUpdate:213 - 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 ''order'
add index FKD2F26980230E719A (customer_id),
add constr' at line 1

原因:

建订单表的时候,表的名字用的是order,由于order是mysql的关键字,因为hibernate生成表的时候依赖的是mysql,所以解析的时候就会报错。但是用可视化工具建表时,表名是order是可以的。


解决方法和注意事项:

在网上查找说可以用分号、小括号或者中括号,但是试了好像都不可以。

1.在建表的时候尽量避免关键字,表名尽量使用x_xxx这样就不会和关键字冲突了,表名一般小写。

2.不要使用mysql的保留字。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值