Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 在SpringBoot中不回滚_Spring Boot_Transactions - Fatal编程技术网

Spring boot 在SpringBoot中不回滚

Spring boot 在SpringBoot中不回滚,spring-boot,transactions,Spring Boot,Transactions,我想创建一个事务性方法,以便在发生任何错误时删除数据库中的插入 我的测试: 我称之为checkNamespaceAndService.getNamespace是成功的,所以可以,但由于验证原因,deployment.setGitCommit失败。因此会抛出一个异常 但在数据库中,保留第一种方法的结果 @Transactional(rollbackFor=Exception.class) public HistoriqueDeploiement saveHistoriqueDeploiem

我想创建一个事务性方法,以便在发生任何错误时删除数据库中的插入

我的测试: 我称之为checkNamespaceAndService.getNamespace是成功的,所以可以,但由于验证原因,deployment.setGitCommit失败。因此会抛出一个异常

但在数据库中,保留第一种方法的结果

@Transactional(rollbackFor=Exception.class)
    public HistoriqueDeploiement saveHistoriqueDeploiementMethod(HistoriqueDeploiementReadingDTO historiqueDeploiementReadingDTO) throws InternalServerErrorException {
        try {       
            Namespace namespace = checkNamespaceAndService.getNamespace(historiqueDeploiementReadingDTO.getNamespace());
            Service service = checkNamespaceAndService.getServices(historiqueDeploiementReadingDTO.getService());
    
            HistoriqueDeploiement deploiment = new HistoriqueDeploiement();
            deploiment.setNamespace(namespace);
            deploiment.setService(service);
            deploiment.setGitCommit(historiqueDeploiementReadingDTO.getGit_commit());
            deploiment.setTagVersion(historiqueDeploiementReadingDTO.getTag_version());
            deploiment.setActionBy(historiqueDeploiementReadingDTO.getAction_by());
            
            historiqueDeploiementRepository.save(deploiment);
            log.info("[Historisation] Ajout réalisé pour -> Namespace : " + historiqueDeploiementReadingDTO.getNamespace() + " -> Service : " + historiqueDeploiementReadingDTO.getService() + " -> Tag : " + historiqueDeploiementReadingDTO.getGit_commit());
            return deploiment;
        }catch(Exception e) {
            log.error("[Historisation] Ajout réalisé pour -> Namespace : " + historiqueDeploiementReadingDTO.getNamespace() + " -> Service : " + historiqueDeploiementReadingDTO.getService() + " -> Tag : " + historiqueDeploiementReadingDTO.getGit_commit());
            log.warn("[@Transactional] Rollback exécuté");
            throw new InternalServerErrorException("Une erreur est survenue lors de l'ajout de l'historique de déploiement");
        }
    }
在我的主课上:

@SpringBootApplication
@EnableTransactionManagement // Added for testing, because without it does not work too.

我希望有人知道为什么不调用回滚。

您是从同一个类调用save方法还是从不同的类调用save方法;在我从控制器调用的事务性方法中:SaveHistoryQuedeLoviementMethod