0

I am currently trying to set the Storage Engine for a table, because from case to case MyISAM and InnoDB should be used. Unfortunately I did not find a way to set this in Hibernate, and I do not want to create each table by hand. My prefered way would be to anotate it in the Java-POJO, but I couldn't find a way to do so.

I've found Hibernate: what's the difference between MySQLDialect and MySQLInnoDBDialect?, which tells me that setting the Dialect to org.hibernate.dialect.MySQLMyISAMDialect would help (it says this for the InnoDB-Dialect, but it seems like one could choose the default dialect with this), but this method has two shortcommings: First, the dialect is chosen for all tables, and second, it creates a query like CREATE TABLE xy(..) type=MyISAM but the query would be correct with engine=MyISAM.

Also Hibernate mysql innodb says that there are defaults, and that I can overwrite them when creating tables, but not how - does somebody know how to do this?

1 Answer 1

2

Instead of org.hibernate.dialect.MySQLMyISAMDialect or org.hibernate.dialect.MySQLInnoDBDialect, you should use org.hibernate.dialect.MySQL5MyISAMDialect or org.hibernate.dialect.MySQL5InnoDBDialect.

This way, it creates the table using engine=MyISAM or engine=InnoDB.

But this configuration is global and if you really have a reason to configure it for a single table, you could try:

  • Hibernate import SQL (hibernate.hbm2ddl.import_files). Add the path to a SQL file which contains the alter table into it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.