• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Cascading Delete  RSS feed

 
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!!
 
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
Boost this thread!