gpt4 book ai didi

java - 请求处理失败;嵌套异常是 org.springframework.transaction.IllegalTransactionStateException

转载 作者:行者123 更新时间:2023-11-29 05:27:41 26 4
gpt4 key购买 nike

你能帮我解决这个错误吗

HTTP Status 500 - Request processing failed; nested exception is org.springframework.transaction.IllegalTransactionStateException: Transaction is already completed - do not call commit or rollback more than once per transaction

代码

@Override
public String saveTemplatesToPCA(List<FilesTemplateDomain> fileTemplates) {
TransactionDefinition transactionDefinition = new DefaultTransactionDefinition();
TransactionStatus status = transactionManager.getTransaction(transactionDefinition);
try {
template.saveOrUpdateAll(fileTemplates);
transactionManager.commit(status);

return "success";
} catch (Exception e) {
transactionManager.rollback(status);
System.out.println("Exception in saveTemplatesToPCA() : "+e);
return "fail";
}
}

最佳答案

处理这个异常

@Override
public String saveTemplatesToPCA(List<FilesTemplateDomain> fileTemplates) {
TransactionDefinition transactionDefinition = new DefaultTransactionDefinition();
TransactionStatus status = transactionManager.getTransaction(transactionDefinition);
try {
template.saveOrUpdateAll(fileTemplates);
transactionManager.commit(status);

return "success";
} catch (Exception e) {
try{
transactionManager.rollback(status);
}catch(Exception ee){
System.out.println("Exception in commit or rollback : "+ee);
}
System.out.println("Exception in saveTemplatesToPCA() : "+e);
return "fail";
}
}

关于java - 请求处理失败;嵌套异常是 org.springframework.transaction.IllegalTransactionStateException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22148197/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com