Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

org.hibernate.annotations.CascadeType.DELETE_ORPHAN

 
rani vini
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know that what is "CascadeType.DELETE_ORPHAN" -- if a child is dereferenced by a persistent parent and if DELETE_ORPHAN is used, the "orphaned" child is deleted.
But I want to know the real time scenario, where this will be useful. Can anyone explain with small example code?


Thanks in advance.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rani vini wrote:I know that what is "CascadeType.DELETE_ORPHAN" -- if a child is dereferenced by a persistent parent and if DELETE_ORPHAN is used, the "orphaned" child is deleted.
But I want to know the real time scenario, where this will be useful. Can anyone explain with small example code?


Thanks in advance.


Order Header to Order Details. I have an order where I buy line items. If I delete the order, those line items make absolutely no sense to keep, so I would definitely want the deleted from the database when an order is deleted.

Sorry don't have any sample code, but the following line of code would delete the order and all its order details, rather than me having to loop through all the children and call delete on each one.

em.delete(order);

Mark
 
rani vini
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If we put Casecade.ALL then the samething will happen...right?
I mean to say if we'll put Casecase.ALL ....whenever user deletes parent, childs also get delete...right?
 
rani vini
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can any one answer this question?

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic