Spring Data Transaction spanning multiple Repositories

Viewed 8211

I have the need to insert 2 different entities into 2 different tables, using the same transaction. If the second insert fails, the first one should be rolled back.

Is there any way of doing this nicely?

Pseudo code:

start tx
repo1.save(myEntity);
repo2.save(anotherEntity);
try commit

I know you can leverage @Transactioal but only on method level?

3 Answers
Related