环境 hibernate5.2.17、MySQL5.5,采用JPA注解配置
1. The First
配置文件:peresistence.xml
//...其它略...
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.hbm2ddl.auto" value="create" />
运行TestApp,报了异常
异常:
2018-09-15 15:46:06 WARN ExceptionHandlerLoggedImpl:27 - GenerationTarget encountered exception accepting command : Error executing DDL via JDBC Statement
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 21
原因:
MyISAM引擎不支持外键,创建不了表并报错 。
MySQLDialect是MySQL5.X之前的版本,其默认的引擎是MyISAM。部分源码如下: