在这里,我提供了引发异常的休眠项目代码
例外:
org.hibernate.StaleObjectStateException:Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect):
当我们调用下面提到的方法时,我想让这个线程安全
public String saveAnswer(String assignmentid, String answerid, String answer) throws Exception {
getStudentManager().logRequestedAnswer(answerid, answer);
User user = getUserManager().getCurrentUser();
HttpSession session = WebContextFactory.get().getSession();
int practiceElapsedTime = getStudentManager().touchPracticeTime(assignmentid, session);
long practiceUpdateTime = ((Date) session.getAttribute("student_current_practice_last_update")).getTime();
StudentAnswer savedAnswer = getStudentManager().saveAnswer(user, assignmentid, answerid, answer);
Map<String, Object> result = new HashMap<String, Object>();
result.put("answerid", savedAnswer.getAnswerKey().getObjectid());
result.put("answer", savedAnswer.getAnswer());
//we're synching the client's time with the server on saves
result.put("practiceElapsedTime", practiceElapsedTime);
result.put("practiceUpdateTime", practiceUpdateTime);
if (savedAnswer.getAssignmentStatus().isCompleted())
result.put("progress", savedAnswer.getAssignmentStatus().getPercent());
else
result.put("progress", savedAnswer.getAssignmentStatus().getProgress());
StringWriter json = new StringWriter();
ObjectMapper mapper = new ObjectMapper();
mapper.writeValue(json, result);
return json.toString();
}