Hibernate Tip: How to delete child entities from a many-to-one association

preview_player
Показать описание

For some many-to-one associations, the child entity can’t exist without its parent. A typical example is the OrderItem which can’t exist without the Order. When you remove the association between the OrderItem and the Order, you need to delete that OrderItem entity as well. So, what’s the easiest way to implement that?

The JPA specification provides the orphanRemoval feature for these use cases. When you activate it on the association, Hibernate removes a child entity when you remove its association to the parent entity.

If you like this video, please give me your thumbs up and share it with your friends and co-workers.

Like my channel? Subscribe!

Join the free Member Library:

Read the accompanying post:

Want to connect with me?
#Hibernate #JPA #HibernatTips
Рекомендации по теме
Комментарии
Автор

title say MANYTOONE... IN THE VIDEO APPEAR ONETOMANY BRO.

christiansanchez
Автор

So book Id with 1 also delete ??
Why we aren't deleting directly book with id 1 and it should automatically delete all associated review object

MohammedImran-hhrg
Автор

I thought it was going to take me some time to make it work but it took 3 minutes :) thanks!😁

wis
Автор

Thanks! It will be if you share code snippet too.

Beatsmusic
Автор

This video is too confusing, you didn't show the class definition of child at all.. Its hard to understand by just looking a parent class definition

basavaraj
Автор

Thank you for the fast nevertheless excellent tutorial.

guilhermelopes
Автор

Thank you, after many hours, it works :D

NicolasShao