Hibernate 配置 MySQL dialect 解决由MySQL版本导致的问题

Hibernate 配置 MySQL dialect 解决由MySQL版本导致的问题

环境:

MySQL版本:Server version: 5.7.19 MySQL Community Server (GPL)

MySQL 驱动版本:5.1.44

Hibernate 版本:5.2.11.Final

hibernate.cfg.xml配置:


<property name="dialect">org.hibernate.dialect.MySQLDialectproperty>

出现的问题现象:

WARN: GenerationTarget encountered exception accepting command : Error executing DDL via JDBC Statement
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL via JDBC Statement
    at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67)
    at org.hibernate.tool.schema.internal.SchemaCreatorImpl.applySqlString(SchemaCreatorImpl.java:440)
    at org.hibernate.tool.schema.internal.SchemaCreatorImpl.applySqlStrings(SchemaCreatorImpl.java:424)
    at org.hibernate.tool.schema.internal.SchemaCreatorImpl.createFromMetadata(SchemaCreatorImpl.java:315)
    at org.hibernate.tool.schema.internal.SchemaCreatorImpl.performCreation(SchemaCreatorImpl.java:166)
    at org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:135)
    at org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:121)
    at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:155)
    at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:72)
    at org.hibernate.internal.SessionFactoryImpl.(SessionFactoryImpl.java:313)
    at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:452)
    at org.hibernate.boot.internal.MetadataImpl.buildSessionFactory(MetadataImpl.java:170)
    at com.xlttdy.hibernate.SimpleUseInHibernate.main(SimpleUseInHibernate.java:18)
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 1
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)

Hibernate 配置 MySQL dialect 解决由MySQL版本导致的问题_第1张图片

Hibernate 配置 MySQL dialect 解决由MySQL版本导致的问题_第2张图片

解决办法:

hibernate.cfg.xml配置:

 
 <property name="dialect">org.hibernate.dialect.MySQL57Dialectproperty>

注意 MySQL57Dialect 与 所用的MySQL 版本是5.7.19的关系。

你可能感兴趣的:(hibernate)