user
user

Reputation: 4830

Spring transactions - detecting rollback and commit

I have methods annotated @Transactional and I would like to detect rollbacks and commits.

Does exist any way or any Spring object which can check if transaction was commited or rollbacked?

Upvotes: 1

Views: 406

Answers (2)

piotrek
piotrek

Reputation: 14550

just run your @Transactional method and then, in another transaction, check what's in db.

and remember to make your tests clean/prepare db before each test (after all the last one could have committed something)

Upvotes: 0

eyupaksu
eyupaksu

Reputation: 271

you can write a unit test cases which is using h2 in-memory database and it will acts like a real db. for example save(obj) and after get(obj).

Also you can write test case which is catch exception that is what you expect(probably when occur a rollback there is also a exception) with this format: @Test(expected = Exception.class) Testclass

Upvotes: 1

Related Questions