• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cascading Delete

 
Steve Daskam
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am trying to do a cascading delete for a one-to-many relationship in hibernate, which works OK, but does not perform efficiently. When hibernate performs the delete, it issues a separate delete statement for each child object. What do I have to do to tell hibernate to use the foreign key of the parent object to perform the delete in one shot (instead of deleting each individual child object separately)? Below is my code:





Thanks!!
 
Aurelian Tutuianu
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to do:
1. Don't use cascade for delete on line items.
2. Create a named query containing a delete statement ( like "delete from li LineItem li where li.order = rder" )
3. The delete method should do:
- get the instance of order
- get the named query
- set the order parameter to named query
- call executeUpdate on named query (now all items are deleted)
- delete the order
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic