tags:

views:

17

answers:

1

I'm trying to write an equivalent of Rails data model evolution/rollback mechanism using Spring Jdbc.

Spring Jdbc transactionnal insert/replace works very well (DataSourceTransactionManager with PROPAGATION_REQUIRED under InnoDB mysql 5) :

// Transaction begins
getJdbcTemplate().execute("replace into aTable ...");
getJdbcTemplate().execute("wrong request");
getJdbcTemplate().execute("replace into aTable ...");
// none are commited

but alter doesn't :

// 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

Is there a way to achieve atomicity (all-or-none behavior) with alter ?

Thanks in advance

+3  A: 

ALTER TABLE (and other DDL operations) are usually non-transactional, depending on the database. Spring and JDBC have no control over this. If a non-transactional operation is performed inside a transaction, it will be performed non-transactionally.

So it comes down to the database, and how it is configured, rather than being an issue with the client.

skaffman
Thanks, I will look in this direction.
Philippe Blayo