liquibase.update() call in Junit Test Not rolling back with Transaction -- Help?

Someone can correct me if I am wrong, but Liquibase makes a commit call as part of the update() method assuming no problems/exceptions are encountered. 

I’ve never tried this, but maybe I will, guessing that the commit followed by the framework rollback means that the work done by Liquibase is committed and then there’s really nothing left to rollback by the time the testing framework calls rollback.

Folks,


I am trying to set up a database with test data for unit tests I want to run.  I am using mysql as the database.  Despite putting annotations on my unit test to be transactional, the liquibase changes are still present after the transaction presumably is rolled back (by spring).


I can’t use HSQL (I think) because I am reading/writing to multiple schemas in mysql–I can’t isolate calls to the separate schemas.


I setup Liquibase within junit by following this helpful blog entry:  http://tech-tauk.blogspot.com/2011/02/unit-test-framework-with.html


Here’s my code.  Any help is much appreciated!



Note the last property where I'm explicitly stating not to auto commit.




Thank you!!

I noticed in my code that I was closing the connection after the liquibase.update() call.  I removed that, but still the transaction isn’t getting rolled back.

Thinking that I was getting the connection from my datasource not wrapped by spring’s transaction management code, I passed in the actual Spring session and called the (deprecated) method, connection().  It didn’t change anything, liquibase’s changes weren’t rolled back.

Yes mike, liquibase does do an explicit commit after ever changeSet, so even though the method is marked as @Transactional, it will still be committed. 


Depending on what changes you have in your changeSet, create/alter/drop statements are usually autocommittting on most databases as well.


Nathan