Quantcast
Channel: Liquibase Forums
Viewing all articles
Browse latest Browse all 2993

Re : rollbacks not working if Spring starts them even if runInTransaction=false

$
0
0
Sorry, I didn't read your original question well enough to really understand what you are doing. 

The problem you are running into is that after each changeSet, liquibase does a connection.commit(), and so when you call rollback after it is done, there is nothing to roll back.

Before each changeSet, liqiubase will run connection.setAutoCommit(!runInTransaction) so by having it set to false it will also automatically commit after each insert and therefore not roll back.

There is nothing built into liquibase to control the fact that it commits after each changeSet, but you should be able to easily override the behavior in your tests. 

SpringLiquibase has a `createDatabase(Connection c)` method which creates a liquibase.database.Database instance based on the connection. It is that Database object's commit() method that is called after the changeSet is ran so if create a subclass of SpringLiquibase that overrides createDatabase() to return a delegate pattern object that delegates all Database methods except commit() to the normal Database object and just replace commit() with a no-op.  That should keep the changeSets from committing when in your test cases and the outer connection rollback() will roll back the changes.

Just remember that some database operations like CREATE TABLE auto-commit and there is no way to avoid that besides using a different database.

Nathan

Viewing all articles
Browse latest Browse all 2993

Trending Articles