As in the title, when performing the update operation, the previous child loses the reference to the parent.
Parent side
@OneToMany(cascade =CascadeType.ALL)
@JoinColumn(name = "individual_id")
private List<ContactMedium> contactMedium;
Children side
@Entity
@Table(name = "contactMedium")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ContactMedium
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id ;
@ManyToOne
private Individual individual;
Patch operation
public Individual patch(Individual individual, Long id) {
Individual objectToSave = individual;
objectToSave.setId(id);
return individualRepository.save(objectToSave);
}
When updating, the previous property loses references to the child. How can I prevent this?