• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Cascading Delete

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!
 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic