Hibernate与Mysql 5.5创建表出错--table doesn't exist

时间:2021-10-18 22:21:29

最近在学习hibernate,利用其自动创建表时老是出错,出错信息如下:

ERROR: HHH000388: Unsuccessful: create table NEWS (ID integer not null auto_increment, TITLE varchar(255), AUTHOR varchar(255), DATE date, primary key (ID)) type=InnoDB
2015-12-24 13:50:38 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 'type=InnoDB' at line 7
2015-12-24 13:50:38 org.hibernate.tool.hbm2ddl.SchemaUpdate execute

经过分析,可以看出提示在type=InnoDB这里出错,将hibernate自动生成的建表语句

create table NEWS (ID integer not null auto_increment, TITLE varchar(255), AUTHOR varchar(255), DATE date, primary key (ID)) type=InnoDB

在mysql下运行同样报错,经查资料发现是这么一回事:
在mysql 5.0版本以后不支持 type=InnoDB 关键字,需要使用 engine=InnoDB
解决放下如下:
在hinernate.cfg.xml配置文件中修改本地方言即可:

<!--原来用的是MySQLInnoDBDialect,改为MySQL5Dialect即可-->
<!-- <property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property> -->
<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>