Win a copy of Microservices in Action this week in the Web Services forum!
  • 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:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!