• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Delete/update associations question

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have mapped User --> UserProduct association(one-to-many) in hibernate as follows:


I also have User class and UserProduct classes as follows:


Here is the part of User.hbm.xml that shows the association:


Here is the UserProduct.hbm.xml file.


How do I delete all userProducts for a given User ?

When I load a user in the Hibernate session and do the following:


The user records do not get deleted !

Can someone show me the correct way to modify hibernate associations.
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think I'll shimmy this on over to our ORM forum where folk talk about Hibernate on a regular basis.
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Change your User hbm to contain:



And the code:



Also, have a look at the "Cascading lifecycle" section at Hibernate reference - Parent child example
 
Naveen Sampra
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much for the reply and the useful link.

You are precisely correct. I was missing cascade="all-delete-orphan". That fixed the problem.
 
reply
    Bookmark Topic Watch Topic
  • New Topic