Invalid syntax error "type= MyISAM" in DDL generated by Hibernate
When creating a table in Hibernate using MySQL as the underlying database, you may encounter an error stating "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'type = MyISAM' at line 1."
Cause:
This error typically occurs because the MySQLDialect dialect used for generating the table definition is not suitable for the version of MySQL or MariaDB you are using. In Hibernate versions 5.x and earlier, the MySQLDialect is designed for MySQL 4.x or earlier, which included the "type = MyISAM" syntax. However, in MySQL 5.5 and later, this syntax is deprecated and needs to be replaced with "ENGINE = MyISAM."
Solution:
To resolve this error, you should update the dialect used by Hibernate to one that is compatible with your database version:
Configuration:
In the provided configuration file, you are using org.hibernate.dialect.MySQLDialect, which is not appropriate for MySQL 5.5 or later. You need to update the configuration to use one of the compatible dialects mentioned above. For example:
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
Note for Hibernate 6:
In Hibernate 6, the dialects will configure themselves based on the actual connected version. Therefore, if you are using Hibernate 6, you should revert to using MySQLDialect or MariaDBDialect.
The above is the detailed content of Why Does Hibernate Generate Invalid 'type=MyISAM' Syntax in MySQL/MariaDB and How Can I Fix It?. For more information, please follow other related articles on the PHP Chinese website!