我想写一个等效的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