I want to update a MongoDB document containing a dbrf lazy attribute using spring data. First of all, I load the existing document, I change the attributes I want and after that, I call @Repository save method, but when I check the document in MongoDB the dbrf lazy attribute is null.
I tried to load the attribute before by calling getAttribute, but that doesn't fix the problem.
Someone could help me? Thanks
I have the Collection below:
@Data
@Document(collection = "calendriers")
public class CalendrierEntity {
@Id
@AutoGenerate(SequanceKey.CALENDRIER)
private Long id;
@NotNul
private String label;
@NotNull
private HorairesEntity horairesEntity;
@DBRef(lazy = true)
@CascadeSave
@Getter(AccessLevel.NONE)
private List<AbsenceEntity> absenceEntities;
}
and the repository bellow :
@Repository
public interface AbsenceRepository extends MongoRepository<CalendrierEntity, Long> {
AbsenceEntity findById(Long enfantId, LocalDate localDate);
}
I have calendrier document with Id 1L and want to update his label. The calendrier document have allready a list of Absences.
this my code to update the label.
@Transactional
public void updateLabelCalendrier(Long id, String label){
CalendrierEntity calendrier = calenderRepository.findById(1L);
calendrier.setLabel(label);
calenderRepository.save(calendrier);
}
but when i check data in mongodb, i have the new label but my list of absences became null.