Hibernate: Create Mysql InnoDB tables instead of MyISAM

54,237

Solution 1

Can't you specify the Hibernate dialect and use

hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect

Edit

From MySQL version > 5.1 this should be

hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect

to avoid running into this issue Using "TYPE = InnoDB" in MySQL throws exception

Solution 2

Go to this link:

mysql-dialect-refactoring

It clearly says :

Traditionally, MySQL used the non-transactional MyISAM storage engine, and this is the default storage engine for all Dialects that are older than MySQL55Dialect. From MySQL55Dialect onwards, the InnoDB storage engine is used by default.

Put the following in your application.properties (or in your config):

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL55Dialect

Notice 55 in above. - not just 5.

And you can see it in the console too:

Hibernate: create table users_events (user_id bigint not null, event_id bigint not null) engine=InnoDB
Hibernate: create table users_roles (user_id bigint not null, role_id bigint not null) engine=InnoDB

Hope it helps.

Solution 3

Are you specifying the dialect setting in your hibernate configuration? If not, then Hibernate will attempt to auto-detect the database dialect, and will choose the safest MySQL dialec, which is MySQL 4 MyISAM.

You can give it a specific dialect, by adding this to your hibernate properties:

hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect

Solution 4

With spring-boot 2.0.0M7 following did work for me (mysqld 5.7)

spring.jpa.hibernate.use-new-id-generator-mappings: true
spring.jpa.database-platform: org.hibernate.dialect.MySQL5InnoDBDialect

Solution 5

As of Hibernate 5.2.8, the Mysql*InnoDBDialect classes used by the other answers are deprecated. The new solution is to set the following property:

hibernate.dialect.storage_engine = innodb

See http://in.relation.to/2017/02/20/mysql-dialect-refactoring/ for more details.

Share:
54,237
David Tinker
Author by

David Tinker

Updated on March 25, 2021

Comments

  • David Tinker
    David Tinker about 3 years

    How can I get Hibernate (using JPA) to create MySQL InnoDB tables (instead of MyISAM)? I have found solutions that will work when using Hibernate to generate an SQL file to create the tables, but nothing that works "on the fly".