我有另一個想法。 ibatis
調用insert方法的委託類:com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate,with the code
:
try {
trans = autoStartTransaction(sessionScope, autoStart, trans);
SelectKeyStatement selectKeyStatement = null;
if (ms instanceof InsertStatement) {
selectKeyStatement = ((InsertStatement) ms).getSelectKeyStatement();
}
// Here we get the old value for the key property. We'll want it later if for some reason the
// insert fails.
Object oldKeyValue = null;
String keyProperty = null;
boolean resetKeyValueOnFailure = false;
if (selectKeyStatement != null && !selectKeyStatement.isRunAfterSQL()) {
keyProperty = selectKeyStatement.getKeyProperty();
oldKeyValue = PROBE.getObject(param, keyProperty);
generatedKey = executeSelectKey(sessionScope, trans, ms, param);
resetKeyValueOnFailure = true;
}
StatementScope statementScope = beginStatementScope(sessionScope, ms);
try {
ms.executeUpdate(statementScope, trans, param);
}catch (SQLException e){
// uh-oh, the insert failed, so if we set the reset flag earlier, we'll put the old value
// back...
if(resetKeyValueOnFailure) PROBE.setObject(param, keyProperty, oldKeyValue);
// ...and still throw the exception.
throw e;
} finally {
endStatementScope(statementScope);
}
if (selectKeyStatement != null && selectKeyStatement.isRunAfterSQL()) {
generatedKey = executeSelectKey(sessionScope, trans, ms, param);
}
autoCommitTransaction(sessionScope, autoStart);
} finally {
autoEndTransaction(sessionScope, autoStart);
}
可以看出,插入和選擇操作是在交易。所以我認爲插入方法沒有共同性問題。
所以你認爲它會導致問題。我的另一個問題是關於如何獲取INSERT INTO .. RETURNING ..語句到ibatis(因爲我不能在這裏發佈鏈接,所以我在問題的末尾添加了它) – Christoph 2009-11-20 14:07:50
當然會。試試psql的2個連接。 至於ibatis - 我不知道它是什麼,但它看起來與java有關 - 這意味着我無法幫助。 – 2009-11-20 14:55:16