ι 版权声明:本文为博主原创文章,未经博主容许不得转载。java
当使用的mysql数据库为5.5版本时,方言须要设置为mysql
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
而非sql
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
二者设置方式的主要差异在于,Hibernate自动生成的sql 建表语句中,对数据库存储引擎的设置不一样。数据库
对于实体类User来讲:spa
public class User { private int id; private String username; private String password; private String sex; private String address; ....... }
采用第一种设置,Hibernate生成的sql建表语句为:hibernate
Hibernate:
create table tuser (
id integer not null auto_increment,
username varchar(255),
password varchar(255),
sex varchar(255),
address varchar(255),
primary key (id)
) engine=MyISAM
经过Hibernate自动建表成功!code
采用第二种设置,Hibernate生成的sql建表语句为:server
Hibernate: create table tuser ( id integer not null auto_increment, username varchar(255), password varchar(255), sex varchar(255), address varchar(255), primary key (id) ) type=MyISAM
经过Hibernate自动建表失败,且报错:blog
....... org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL via JDBC Statement ........ Caused 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=MyISAM' at line 8 ........
报错缘由:rem
虽然TYPE=MyISAM 和 ENGINE=MyISAM 都是设置数据库存储引擎的语句 。
可是老版本的Mysql使用Type,新版本的Mysql使用ENGINE。
虽然MySQL 5.1为向下兼容而支持这个语法,但TYPE如今已经被轻视,ENGINE才是首选的用法。
通常状况下咱们是无需考虑ENGINE的,除非你的mysql的默认数据库存储引擎为非ENGINE了。