+-
java-具有alter table的Spring Jdbc原子性
我正在尝试使用 Spring Jdbc编写等效的Rails数据模型演化/回滚机制.

Spring Jdbc transactionnal插入/替换工作得很好(在InnoDB mysql 5下具有PROPAGATION_REQUIRED的DataSourceTransactionManager):

// 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实现原子性(全或全行为)?

提前致谢

最佳答案
ALTER TABLE(和其他 DDL操作)通常是非事务性的,具体取决于数据库. Spring和JDBC无法对此进行控制.如果在事务内部执行非事务性操作,则将以非事务性方式执行.

因此,它取决于数据库及其配置方式,而不是客户端的问题.

点击查看更多相关文章

转载注明原文:java-具有alter table的Spring Jdbc原子性 - 乐贴网