I am taking the insurance details from user and saving them in a hashmap. And I have button called SAVE. So only, when user clicks on this button all insurances should save in Database So I am taking a random generated id as reference until I save the details in Database After saving in database, I need to update this hashmap with key as autogenerated id
public void saveInformationInDatabase(int patientId)
{
// getAllInsurances returns HashMapn<Integer, HashMap<Integer, InsuranceInformation>>
Iterator<Map.Entry<Integer, InsuranceInformation>> insurances = getAllInsurances().get(patientId).entrySet().iterator();
while(insurances.hasNext())
{
InsuranceInformation insuranceInformation = insurances.next().getValue();
if (insuranceInformation.getStatus() == Status.OLD)
continue;
else if (insuranceInformation.getStatus() == Status.NEW)
{
// Saving the Information in database, and returning auto generated ID
int licId = saveInformation(insuranceInformation);
// So, i need to update insuranceInformation with autogenerated ID
// Because previous id is randomly generated number
insuranceInformation.setLicID(licId);
insuranceInformation.setStatus(InsuranceObject.Status.OLD);
// Below line gives me ConcurrentModificationException
getAllInsurances().get(patientId).put(licId, insuranceInformation); // Storing the updated information with newly generated id as key, in hashmap
insurances.remove(); // and here, removing the old hashmap entry
}
}
}