I have an Android application where there is a week table and a visit table. The visits table has a 1:n relationship with the week table. In this way, the visit has a reference to the week through an object. However, when updating the week, the visit table loses the week reference. I do not change the primary key, I only update the other fields. What could be happening?
JsonObject semanaJson = semanasArray.get(auxI).getAsJsonObject();
Semana semana = (Semana) semanaRepo.getById(semanaJson.get("id").getAsInt());
if (semana == null) {
semana = semanaRepo.getObject(semanaJson);
}
semana.mergeWithJSON(semanaJson);
public void mergeWithJSON(JsonObject jsonObject) {
@SuppressLint("SimpleDateFormat")
SimpleDateFormat formatter = new SimpleDateFormat(DateFormats.DATA);
setNome(jsonObject.get("nome").getAsString());
try {
setDiaInicial(formatter.parse(jsonObject.get("data_inicio").getAsString()));
} catch (ParseException e) {
Sentry.captureException(e);
throw new RuntimeException(e);
}
try {
setDiaFinal(formatter.parse(jsonObject.get("data_fim").getAsString()));
} catch (ParseException e) {
Sentry.captureException(e);
throw new RuntimeException(e);
}
Date dataInicio = getDiaInicial();
Date dataFinal = getDiaFinal();
Calendar cal = Calendar.getInstance();
cal.setTime(dataInicio);
cal.set(Calendar.HOUR_OF_DAY, 00);
cal.set(Calendar.MINUTE, 00);
cal.set(Calendar.SECOND, 00);
setDiaInicial(cal.getTime());
cal.setTime(dataFinal);
cal.set(Calendar.HOUR_OF_DAY, 23);
cal.set(Calendar.MINUTE, 59);
cal.set(Calendar.SECOND, 59);
setDiaFinal(cal.getTime());
}