我們都知道這是事務的註解,如果發生異常會進行回滾,可誰知道他還有另一個作用
在我們開發中經常會有一些單元測試代碼,在測試數據庫的時候,我們會有一些測試數據,但是在運行過程中數據庫中不應該有這些測試數據,
@Transactional可以解決這個問題
@Test
@Transactional
public void updateTest()
{
ProductCategory productCategory = new ProductCategory();
productCategory.setCategoryName("");
productCategory.setCategoryType(2);
productCategory.setCategoryId(1);
repository.save(productCategory);
}
這樣這個事務就一定會回滾!