我嘗試回滾我的DB變化org.springframework.jdbc DB回滾不會恢復狀態
的roollback代碼也不例外運行,但我的DB是髒的變化。
我錯過了什麼?
final Connection dbConnection = rulesUiRepository.getConnection();
dbConnection.setAutoCommit(false);
try {
if (rulesUiRepository.updateRulesUiSnapshot(this.nonSplittedRulesSnapshot) == -1)
throw new RuntimeException("cannot save ui snapshot to DB");
...more code
} catch (Exception e) {
logger.error("transaction to update db and cofman failed", e);
//did work
//dbConnection.rollback();
throw new Exception("transaction to update db and cofman failed", e);
} finally {
//or
if (dbConnection != null) {
dbConnection.close();
}
}
與代碼:
public synchronized void rollback() throws SQLException {
try {
this.txn_known_resolved = true;
this.inner.rollback();
} catch (NullPointerException var2) {
if(this.isDetached()) {
throw SqlUtils.toSQLException("You can't operate on a closed Connection!!!", var2);
} else {
throw var2;
}
} catch (Exception var3) {
if(!this.isDetached()) {
throw this.parentPooledConnection.handleThrowable(var3);
} else {
throw SqlUtils.toSQLException(var3);
}
}
}
回滾爲什麼被註釋掉?你的數據庫是什麼?什麼是實際的代碼唱歌的連接?執行之前和之後的狀態是什麼?發佈一個完整的重現問題的最小例子。這裏有太多的未知數。 –
爲什麼回滾註釋掉了?因爲它不適合我 什麼是您的數據庫? org.springframework.jdbc數據庫回滾不會恢復狀態 –