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

2023-03-14,,

问题:

使用hibernate4.1.1,数据库使用mysql5.1.30,使用hibernate自动生成数据库表时,hibernate方言使用org.hibernate.dialect.MySQLInnoDBDialect,自动生成表时会出现错误。

控制台报错如下:

十一月 28, 2016 4:15:22 下午 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
ERROR: HHH000388: Unsuccessful: create table NEWS (ID integer not null auto_increment, TITLE varchar(255), AUTHOR varchar(255), DATE datetime, primary key (ID)) type=InnoDB
十一月 28, 2016 4:15:22 下午 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

十一月 28, 2016 4:15:22 下午 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000232: Schema update complete

原因分析:

是因为type=InnoDB在5.0以前是可以使用的,但5.1之后就不行了。如果我们把type=InnoDB改为engine=InnoDB就不会有这个问题。

但是,我想使用Hibernate,自动帮我建表,怎么办呢。这就与我们指定的数据库方言(dialect)有关了。

解决办法:
只需要修改配置:

hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect

修改为:

hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect

转载自:http://www.th7.cn/db/mysql/201606/192445.shtml

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的相关教程结束。

《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.doc》

下载本文的Word格式文档,以方便收藏与打印。