我想寫一個等效的Rails數據模型演化/回滾機制使用Spring Jdbc。春季Jdbc原子性與改變表
了Spring JDBC transactionnal insert/replace
作品非常好(的DataSourceTransactionManager與PROPAGATION_REQUIRED下MySQL的InnoDB的5):
// Transaction begins
getJdbcTemplate().execute("replace into aTable ...");
getJdbcTemplate().execute("wrong request");
getJdbcTemplate().execute("replace into aTable ...");
// none are commited
但alter
不會:
// Transaction begins
getJdbcTemplate().execute("alter table aTable add column `columnForTest` ...");
getJdbcTemplate().execute("wrong request");
getJdbcTemplate().execute("alter table aTable add column `columnForTest` ...");
// the first alter is commited
有沒有辦法實現原子性(全 - 或 - 無行爲)與alter
?預先
在運行時添加數據庫列是一個巨大的數據模型設計氣味。你不應該使用鏈接表嗎?這樣您只需將「列名稱」和所需的關聯數據作爲新行插入即可。 – BalusC 2010-07-14 11:45:54