1、现象:hinernate中明明指定了
<property name="hbm2ddl.auto">create</property>
却不能自动建表
这个问题困扰了我很久,原因其实从控制台显示出来的信息就可以看出来
Unsuccessful: create table admin (adminId varchar(255) not null auto_increment, username varchar(255), password varchar(255), primary key (adminId)) ENGINE=InnoDB
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 1
五月 08, 2014 4:39:49 上午 org.hibernate.tool.hbm2ddl.SchemaExport execute
解决方案:
<
property name="hibernate.dialect"
>
.hibernate.dialect.MySQLInnoDBDialect
</property>
修改为:
<
property name="hibernate.dialect"
>
org.hibernate.dialect.MySQL5InnoDBDialect
</
property
>
Unsuccessful: create table admin (adminId varchar(255) not null auto_increment, username varchar(255), password varchar(255), primary key (adminId))
ERROR: Incorrect column specifier for column 'adminId'
五月 08, 2014 4:43:47 上午 org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: HHH000230: Schema export complete
主要是因为我把
adminId设为了String 类型
总结:
今天的这个问题困扰了这么长的时间还是因为我不记着看控制台的信息,只知道把报出的异常进行百度
1、hibernate不能自动建表的原因基本上是因为数据库方言选择的问题。选择最适合自己的方言(最蠢的即使一个个试下)
2、注意适时查看控制台的log信息