ERROR: HHH000388: Unsuccessful: create table

来源:互联网 发布:网络安全书 编辑:程序博客网 时间:2024/06/01 18:56

参考:http://blog.csdn.net/hncmkl/article/details/48272149

做SSH整合的时候,总是出现错误信息:
类似这样:

: HHH000388: Unsuccessful: create table right (right_code varchar(255) not null auto_increment, right_desc varchar(255), right_name varchar(255), right_parent_code varchar(255), right_type varchar(255), right_url varchar(255), primary key (right_code)) ENGINE=InnoDB九月 07, 2015 6:22:44 下午 org.hibernate.tool.hbm2ddl.SchemaUpdate executeERROR: 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 'right (right_code varchar(255) not null auto_increment, right_desc varchar(255),' at line 1

我的表其中一个字段是:

    /*     * 宝贝的描述     */@Column(name = "desc", nullable = false, length = 255)private String desc;

错误是因为字段名和数据库关键字冲突了!!!

在网站找到的一些mysql关键字,注意避免将其用作字段名:

参考: http://www.cnblogs.com/-mrl/p/6021959.html

这里写图片描述

这里写图片描述

这里写图片描述

这里写图片描述

这里写图片描述

如果非要在hibernate中使用数据库关键字(保留字),解决方法可以是:

参考: http://blog.csdn.net/henren555/article/details/10252223

两种方式:

  1. 使用[]
<property name="desc" type="string" >    <column name="[DESC]" length="255" not-null="true" /></property>

注解

@Column(name = "[DESC]", nullable = false)public String getDesc() {    return this.desc;}

2,使用单引号包围双引号

<property name="desc" type="string" >    <column name='"DESC"' length="255" not-null="true" /></property>

注解

@Column(name = "\"DESC\"", nullable = false)public String getDesc() {    return this.desc;}
1 0
原创粉丝点击