Answer the question
In order to leave comments, you need to log in
Spring Data Jpa how to remove an entity without removing another related entity?
I have a Lesson entity:
@OneToMany(mappedBy="lesson", cascade = {
CascadeType.ALL
}, fetch = FetchType.LAZY)
@Getter @Setter
private List<Client> clients = new ArrayList<>();
@ManyToOne
@JoinColumn(name="lesson_ID")
@Getter @Setter
private Lesson lesson;
Answer the question
In order to leave comments, you need to log in
Good afternoon.
You can try the following:
CascadeType.MERGE,
CascadeType.PERSIST
orphanRemovel = false;
orphanRemoval = true,
then if the client has no lessonId, then it will be deleted, since it is an "orphan". And if vice versa is false, then it will not be deleted. Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question