I declared a OneToMany with corresponding ManyToOne as
@OneToMany( cascade = {CascadeType.ALL}, mappedBy="incident")
private Set<CustomIncidentAttribute> cias = new HashSet<CustomIncidentAttribute>(0);
and
@ManyToOne @JoinColumn(name = "INCIDENT_FK")
private Incident incident;
When I removed an entity from the Set, I only noticed that the incident field of the other end was nullified, but the object was not removed.
Then I read that if you want the OneToMany to be the owner, you should define it as:
@OneToMany( cascade = {CascadeType.ALL)
@JoinColumn(name = "INCIDENT_FK")
private Set<CustomIncidentAttribute> cias = new HashSet<CustomIncidentAttribute>(0);
and
@ManyToOne @JoinColumn(name = "INCIDENT_FK", insertable=false, updatable=false)
private Incident incident;
I.e you remove the mappedBy and add the joinColumn.
However I still see the same behaviour that when I remove from a set the other end's incident is just nullified, but the object stays in the DB.
Can you remove an object from a set and actually remove it from the DB also?
|