@Transactional注释的引用

我们都知道这是事务的注解,如果发生异常会进行回滚,可谁知道他还有另一个作用

在我们开发中经常会有一些单元测试代码,在测试数据库的时候,我们会有一些测试数据,但是在运行过程中数据库中不应该有这些测试数据,

@Transactional可以解决这个问题
 @Test
    @Transactional
    public void updateTest()
    {
        ProductCategory productCategory = new ProductCategory();
        productCategory.setCategoryName("");
        productCategory.setCategoryType(2);
        productCategory.setCategoryId(1);

        repository.save(productCategory);



    }

这样这个事务就一定会回滚

猜你喜欢

转载自blog.csdn.net/qq_37992974/article/details/88067124