Исключение "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;
}
Спящее отображение вопроса содержит следующее:
<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: ошибка SQL DB2: SQLCODE=-911, SQLSTATE=40001, SQLERRMC=2, DRIVER=4.14.88. Как я понял, это был тупик. Может кто-нибудь помочь с этим?