配置了数据库方言为MySQLInnoDBDialect之后不能自动建表
dev环境配置为MySQLInnoDBDialect,程序发布到dev环境没问题。dev的库为mariadb5.5.33a。
后来dev数据库迁移,顺便把数据库版本升级到了mariadb10.0,发现不能自动建表,但是忽略了这个问题,直接手动建表程序运行成功。
后来发布qa环境,发现不光不能自动建表,程序还运行报错:
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'type=InnoDB' at line 8
查看MySQLInnoDBDialect的源码:
public class MySQLInnoDBDialect extends MySQLDialect {
public boolean supportsCascadeDelete() {
return true;
}
public String getTableTypeString() {
return " type=InnoDB";
}
public boolean hasSelfReferentialForeignKeyBug() {
return true;
}
看来问题就出在这儿了。在jdbc配置文件里把MySQLInnoDBDialect改成MySQL5InnoDBDialect之后就可以运行了。
查看MySQL5InnoDBDialect源码:
public class MySQL5InnoDBDialect extends MySQL5Dialect {
public boolean supportsCascadeDelete() {
return true;
}
public String getTableTypeString() {
return " ENGINE=InnoDB";
}
public boolean hasSelfReferentialForeignKeyBug() {
return true;
}
}
mysql 5.1之后就应该使用 ENGINE=InnoDB