ERROR: HHH000388: Unsuccessful: create table

参考: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 execute
ERROR: 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
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值