Reputation: 2505
I am using play 2 framework with JPA hibernate. My goal is to get JPA to generate tables on a fresh database using specific ROW_FORMAT:
This is what JPA executes on start:
create table Admin (
..
) ENGINE=InnoDB
And this is what I want:
create table Admin (
..
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC
The persistance.xml looks like this:
<persistence-unit name="defaultPersistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<non-jta-data-source>DefaultDS</non-jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
</properties>
</persistence-unit>
I tried looking for ways to use annotations in the java code, or a specific property in for the XML conf. I had no luck.
Upvotes: 2
Views: 817
Reputation: 23226
You can do it by subclassing MySQL5InnoDBDialect and overriding the getTableTypeString()
method as below.
public class MySQL5CustomInnoDBDialect extends MySQL5InnoDBDialect{
/**
* Call to super returns " type=innodb". 'Type' is a
* deprecated MySQL synonym for 'engine'
* so you may want to ignore the super call and use:
* " engine=innodb ROW_FORMAT=DYNAMIC"
*/
public String getTableTypeString() {
return super.getTableTypeString() + " ROW_FORMAT=DYNAMIC";
}
}
And obviously set this as your dialect:
<property name="hibernate.dialect" value="org.foo.MySQL5CustomInnoDBDialect"/>
Upvotes: 3