执行session.save() 时出现异常:

org.hibernate.exception.SQLGrammarException: could not execute statement

无法创建表。

解决方法:

1)确定配置:

<property name="hibernate.hbm2ddl.auto">update</property>


2)如果是mysql5的话,确定配置:

<property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>

注意红字部分。

MySQLInnoDBDialect,生成的建表语句中用type=InnoDB,

而MySQL5InnoDBDialect是ENGINE=InnoDB