Hibernate與Mysql 5.5創建表出錯--table doesn't exist

最近在學習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>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章