Java 带alter table的Spring Jdbc原子性

Java 带alter table的Spring Jdbc原子性,java,spring,jdbc,Java,Spring,Jdbc,我正在尝试使用SpringJDBC编写Rails数据模型演化/回滚机制的等价物 Spring Jdbc transactionnalinsert/replace工作得很好(InnoDB mysql 5中需要具有传播功能的DataSourceTransactionManager): 但是,alter不会: // Transaction begins getJdbcTemplate().execute("alter table aTable add column `columnForTest` ..

我正在尝试使用SpringJDBC编写Rails数据模型演化/回滚机制的等价物

Spring Jdbc transactionnal
insert/replace
工作得很好(InnoDB mysql 5中需要具有传播功能的DataSourceTransactionManager):

但是,
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
实现原子性(全部或无行为)

提前感谢

更改表
(和其他操作)通常是非事务性的,具体取决于数据库。Spring和JDBC对此没有控制权。如果在事务内部执行非事务性操作,则该操作将以非事务性方式执行


因此,归根结底是数据库,以及如何配置数据库,而不是客户端的问题。

在运行时添加DB列是一个巨大的数据模型设计气味。你不应该使用链接表吗?这样,您只需要插入“列名”和所需的关联数据作为新行。谢谢,我将朝这个方向看。
// 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