小编Bha*_*v J的帖子

Spring boot @Transactional 不回滚数据库插入

这里需要一些帮助,我无法理解为什么我的事务在发生异常时不会回滚。

我会尝试将我的代码尽可能接近项目中的位置(无法在互联网上共享)

这是我的服务

@Service
@SL4j
@Transactional(propagation = propagation.SUPPORTS, readOnly=true)
public class PublicationServiceImpl implements PublicationService{
    @Autowired 
    private PartnerRepo partnerRepo;
                
    @Autowired
    private FlowRepo flowRepo;

    @Autowired
    private PubRepo pubRepo;
                
    @Override
    @Transactional(propagation = propagation.REQUIRED, rollbackFor=Exception.class)
    public int save(Request request) {
    try{
                   int  pk_id_partner = partnerRepo.save(request);
                   int  pk_id_flow = flowRepo.save(request);
        
                   String publicationCode = generatePubCode(request);
                   int publicationCode= pubRepo.save(pk_id_partner, pk_id_flow, request);
        }
        catch(Exception e){
        log.error("Exception in saving");
    }
    return 0;
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的存储库(1 的示例,所有 3 个存储库都遵循相同的编码标准)

@Repository
@Slf4j
public class PartnerRepo implemets PartnerRepo{
    @Autowired
    private NamedParamaterJDBCTemplate namedParamaterJDBCTemplate; …
Run Code Online (Sandbox Code Playgroud)

java spring-transactions spring-boot

6
推荐指数
2
解决办法
2万
查看次数

标签 统计

java ×1

spring-boot ×1

spring-transactions ×1