and one of them is removed from the order, the removed line item is considered an orphan. If orphanRemoval is set to true, the line item entity will be deleted when the line item is removed from the order.
@OneToMany(orphanRemoval="true")
public Set<LineItems> getLineItems() { return lineItems; }
while this one says:
The following example will cascade the remove operation to the orphaned customer entity when it is removed from the relationship:
@OneToMany(mappedBy="customer", orphanRemoval="true")
public List<Order> getOrders() { ... }
My question: Are both examples correct? (I think they are in contradict)
check these posts: 1. https://www.baeldung.com/hibernate-one-to-many 2. https://mkyong.com/hibernate/hibernate-one-to-many-relationship-example-annotation/ 3. https://www.viralpatel.net/hibernate-one-to-many-annotation-tutorial/ 4. https://vladmihalcea.com/the-best-way-to-map-a-onetomany-association-with-jpa-and-hibernate/
Обсуждают сегодня