hibernate生成表时候,注意不能使用mysql关键字和保留字(比如order)
2016-11-24 01:39
501 查看
问题:
今天在用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的保留字。
今天在用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的保留字。
相关文章推荐
- Hibernate&MySQL——Group是关键字,在使用Hibernate时不能将其作为表名
- 使用hibernate和mysql生成数据表时,类型为string的属性对应的数据列不能插入汉字
- 使用hibernate的自动生成表的时候注意事项
- 在使用动软.net代码生成器生成access数据库的时候需要注意的
- mysql字段命名时,避免使用保留关键字
- mysql使用高版本登录低版本的时候注意的问题
- 关于使用Jquery动态生成页面组件的时候,单引号和双引号的注意
- 不能使用Hibernate Reverse Engineering生成实体类的原因
- Mysql多个LEFT JOIN使用ORDER不能使用索引解决方案
- hibernate mysql 谨慎使用mysql关键字
- 用hibernate生成表时,字段名不能为order
- 解决在Oracle数据库中使用hibernate生成表不能正确创建表的问题
- 使用hibernate与mysql时数据不能插入的原因及解决办法
- order是mysql的关键字,不能用order作为表名
- MySQL的保留关键字,使用时尽量避免
- DB2数据库中SQL语句中使用or和and的关键字的时候注意事项
- Mysql中不能使用top关键字,而使用limit关键字
- 解决在oracle数据库中使用hibernate生成表不能正确创建表的问题
- 注意使用PowerDesigner 生成 Oracle表时候带来的问题
- 包含别人的dll,然后我们用类库再次封装成dll的时候的注意事项;源文件与模块生成时的文件不同;创建调试信息文件 ··PDB时发生意外的错误,进程无法访问文件,因为另一个程序正在使用此文件