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".
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".
Go to this link:
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.
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
For newer versions, you can use
hibernate.dialect.storage_engine=innodb
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
Other options for hibernate.dialect can be MySQL55Dialect or MySQL57Dialect
Just in case of Spring Boot 2
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL57Dialect
spring.jpa.properties.hibernate.dialect.storage_engine=innodb
If you are using Hibernate 5.2.8+, try using the MySQL55Dialect, which according to the link provided by Jules, sets innoDB by default as the storage engine.
in case you choose application.yml
spring:
jpa:
properties:
hibernate:
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
Here are the properties from my persistence.xml that fixed it. You can use those in Spring or directly in Hibernate, whatever your dev stack:
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
<property name="hibernate.dialect.storage_engine" value="innodb"/>