Let me get my question straight, using the @OnDelete
here will delete this and any other InventoryPreference
entities if the Inventory
entity is deleted? I just can't understand a thing from Hibernate's annotations reference.. so I need your help to confirm that I understood it correctly.
public class InventoryPreference {
...
@ManyToOne
@OnDelete(action = OnDeleteAction.CASCADE)
@JoinColumn(name = "inventory_id", nullable = false)
public Inventory getInventory() {
return inventory;
}
}
Do I then in the Inventory
entity need to use CascadeType.ALL
too to get all the InventoryPreference
s deleted if the Inventory
entity is deleted?
public class Inventory {
...
@OneToMany(mappedBy = "inventory", cascade = CascadeType.ALL)
public Set<InventoryPreference> getPreferenceItems() {
return preferenceItems;
}
}
If the first question is true, then I don't see the point of CascadeType.ALL
. If it's not then what do each of these do and what annotations and configuration I need to specify to get the InventoryPreference
s deleted when Inventory
is deleted? Oh and I don't want the Inventory
to be deleted if InventoryPreference
gets deleted. Sorry if it's too obvious.