最近遇到了一个问题。在学习使用 Hibernate 5.1.x 版本中, hbm2ddl.auto -> update 无法创建新表,用 JUnit 单元测试报错,表不存在。
排查过程中发现如下
INFO: HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@3276732] 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=InnoDB
关键这个 type=InnoDB 不对
百度一段时间后发现原来在 hibernate.cfg.xml 配置文件中:
<property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
修改配置后可正常运行通过。
经过详细查阅后发现,原来在文档中已经说明。
hibernate-release-5.1.10.Final/documentation/javadocs/org/hibernate/dialect/MySQL5InnoDBDialect.html