Hi, I am trying to understand the OnDelete annotation.
I have a Order class and a OrderItem class....
So far, I understand that if I use the OnDelete annotation on a child object, child objects will be deleted when the parent is deleted.
On a order item...
Code:
@ManyToOne(targetEntity = OrderEnt.class, fetch = FetchType.EAGER, optional = false)
@JoinColumn(name = "order_id", nullable = false)
@ForeignKey(name = "fk_order")
@OnDelete(action = OnDeleteAction.CASCADE)
@Valid
@NotNull
private OrderEnt order;;
this will create DDL containing
Code:
CONSTRAINT fk_order FOREIGN KEY (order_id)
REFERENCES orders (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE CASCADE,
But in the order object I have...
Code:
@OneToMany(targetEntity = OrderItemEnt.class, fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "order")
@OnDelete(action = OnDeleteAction.CASCADE)
@OrderBy("id asc")
@Valid
private Set<OrderItemEnt> orderItems = new HashSet<OrderItemEnt>();
What effect does the @OnDelete(action = OnDeleteAction.CASCADE) have here ???