例外 「org.hibernate.exception.LockAcquisitionException:無法插入」 出現有時下面的代碼:休眠例外:死鎖
Question questionClone;
try {
questionClone = (Question) question.clone();
} catch (CloneNotSupportedException e) {
throw WrappedException.wrap(e);
}
questionClone.setCategory(question.getCategory());
questionClone.setOriginal(false);
logger.trace("Saving questionClone " + questionClone + " start");
hibernateSession.save(questionClone);
logger.trace("Saving questionClone " + questionClone + " end");
時questionClone保存。下面是問題的克隆方法:
public Object clone() throws CloneNotSupportedException {
Question questionClone = (Question) super.clone();
questionClone.category = null;
List<Alternative> alternativesClone = new ArrayList<Alternative>(getInternalAlternatives().size());
int index = 0;
for (Iterator<Alternative> iterator = getInternalAlternatives().iterator(); iterator.hasNext();) {
Alternative alternative = iterator.next();
Alternative alternativeClone = (Alternative) alternative.clone();
alternativeClone.setQuestion(questionClone);
alternativeClone.setIndex(index);
alternativesClone.add(alternativeClone);
++index;
}
questionClone.setInternalAlternatives(alternativesClone);
return questionClone;
}
和克隆的替代方法:
public Object clone() throws CloneNotSupportedException {
Alternative alternativeClone = (Alternative) super.clone();
alternativeClone.index = 0;
alternativeClone.question = null;
return alternativeClone;
}
問題
Hibernate映射包含此:
<list name="internalAlternatives" inverse="true" cascade="all-delete-orphan">
<cache usage="read-write"/>
<key column="QUESTION_ID"/>
<list-index column="INDEX"/>
<one-to-many class="Alternative"/>
</list>
異常狀態,它不能插入替代並導致:com.ibm.db2.jcc.am.SqlTransactionRollbackException:DB2 SQL錯誤:SQLCODE = -911,SQLSTATE = 40001,SQLERRMC = 2,DRIVER = 4.14.88。當我發現這是一個僵局。有人能幫忙嗎?
用戶在開始測試時克隆了這些問題。這可能是由於幾個用戶同時開始測試嗎?爲每個用戶創建單獨的測試會話。 – 2012-07-09 05:52:22