Index: lams_tool_assessment/src/java/org/lamsfoundation/lams/tool/assessment/service/AssessmentServiceImpl.java =================================================================== diff -u -rc0f4a7e33200e148a97d30cb2091ecea22c3cfc7 -r8ed511ea0d10517d2d9b441df3cff4676d651b45 --- lams_tool_assessment/src/java/org/lamsfoundation/lams/tool/assessment/service/AssessmentServiceImpl.java (.../AssessmentServiceImpl.java) (revision c0f4a7e33200e148a97d30cb2091ecea22c3cfc7) +++ lams_tool_assessment/src/java/org/lamsfoundation/lams/tool/assessment/service/AssessmentServiceImpl.java (.../AssessmentServiceImpl.java) (revision 8ed511ea0d10517d2d9b441df3cff4676d651b45) @@ -3439,6 +3439,7 @@ ArrayNode questions = JsonUtil.optArray(toolContentJSON, "questions"); Set newQuestionSet = assessment.getQuestions(); // the Assessment constructor will set up the collection for (JsonNode questionJSONData : questions) { + boolean addToCollection = false; AssessmentQuestion question = new AssessmentQuestion(); @@ -3483,8 +3484,19 @@ JsonUtil.optBoolean(questionJSONData, "incorrectAnswerNullifiesMark", Boolean.FALSE)); qbQuestion.setPenaltyFactor(JsonUtil.optDouble(questionJSONData, "penaltyFactor", 0.0).floatValue()); + // UUID normally gets generated in the DB, but we need it immediately, + // so we generate it programatically. + // Re-reading the QbQuestion we just saved does not help as it is read from Hibernate cache, + // not from DB where UUID is filed + qbQuestion.setUuid(UUID.randomUUID()); assessmentDao.insert(qbQuestion); + // Store it back into JSON so Scratchie can read it + // and use the same questions, not create new ones + uuid = qbQuestion.getUuid().toString(); + ObjectNode questionData = (ObjectNode) questionJSONData; + questionData.put(RestTags.QUESTION_UUID, uuid); + if ((type == QbQuestion.TYPE_MATCHING_PAIRS) || (type == QbQuestion.TYPE_MULTIPLE_CHOICE) || (type == QbQuestion.TYPE_NUMERICAL) || (type == QbQuestion.TYPE_MARK_HEDGING)) {