If I have a bidirectional OneToMany and I remove a related entity from the Set, then call "persist", is the removed related entity supposed to get deleted from the database or not? In my case it is not getting deleted, altough I was under the impression that persist would reflect all changes made to the object graph (my cascade is "ALL"). The removal from the Set is definitely occuring - it's just not getting reflected in the DB.
some code to explain:
Parent:
@OneToMany(mappedBy="form", cascade=CascadeType.ALL, fetch=FetchType.EAGER) public Set<BaseSchedule> getSchedules() { return schedules; }
@ManyToOne public BaseForm getForm() { return form; }
form.getSchedules().remove(someSchedule); em.persist(form); // This is NOT deleting the child
No. You would need to add the (Hibernate-specific) annotation for orphan delete.
Also check your understanding of persist(), it is NOT used in the way you are trying to use it here!