求救spring中事务重复提交问题
首先,有action,service和dao,事务是在service中控制的,下面这些是在service中的方法
public void excuteUpdate()
throws BusinessException {
TransactionStatus status = LocBegin();
try {
doSomethingByDao();
} catch (BusinessException e) {
LocRollback(status);
throw e;
} catch (Exception e) {
this.LocRollback(status);
e.printStackTrace();
throw new BusinessException("000", "unexception!");
}
LocCommit(status);
}
public TransactionStatus LocBegin() throws BusinessException{//事务开始
try{
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
TransactionStatus status = transactionManager.getTransaction(def);
return status;
}catch(TransactionException e){
throw new BusinessException("100", e.getMessage());
}
}
public void LocCommit(TransactionStatus status) throws BusinessException{//事务提交
try{
transactionManager.commit(status);
}catch(TransactionException e){
transactionManager.rollback(status);
throw new BusinessException("101", e.getMessage());
}
}
public void LocRollback(TransactionStatus status) throws BusinessException{//事务回滚
try{
transactionManager.rollback(status);
}catch(TransactionException e){
throw new BusinessException("102", e.getMessage());
}
}
老是报这样的异常:
org.springframework.transaction.IllegalTransactionStateException: Transaction is already completed - do not call commit or rollback more than once per transaction
at org.springframework.transaction.support.AbstractPlatformTransactionManager.rollback(AbstractPlatformTransactionManager.java:551)
at org.dxs.service.UpdateService_Impl.LocCommit(Unknown Source)
说是事务已经提交了,想不明白,代码里就提交了这一次啊