配置資料庫方言為MySQLInnoDBDialect之後不能自動建表
阿新 • • 發佈:2018-10-31
配置了資料庫方言為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