hibernate--MYSQL建表时type=InnoDB和Engine=InnoDB注意点

来源:互联网 发布:淘宝艺术照服装 编辑:程序博客网 时间:2024/05/16 14:15

hibernate初学在配置好一切之后,运行然后报错,接下来问度娘,最后解决。。。
首先看报错

[org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@6cea706c] for (non-JTA) DDL execution was not in auto-commit mode; the Connection 'local transaction' will be committed and the Connection will be set into auto-commit mode.Hibernate:     create table NEWS (       ID integer not null auto_increment,        TITLE varchar(255),        AUTHOR varchar(255),        DATE date,        primary key (ID)    ) type=InnoDBCaused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 7WARN: GenerationTarget encountered exception accepting command : Error executing DDL via JDBC StatementHibernate:     insert     into        NEWS        (TITLE, AUTHOR, DATE)     values        (?, ?, ?)WARN: SQL Error: 1146, SQLState: 42S02ERROR: Table 'hibtest.news' doesn't exist

里面有建表语句:

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

报错也说了

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

我们这里出来问题,这是mysql5.1以前的写法,5.1之后变化如下:

engine = InnoDB

现在找出问题所在,我们只要修改hibernate.cfg.xml中的方言配置就可以了,不需要修改其他的
正确的做法如下:
这里写图片描述

org.hibernate.dialect.MySQL5InnoDBDialect