File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Delete/update associations question

 
Naveen Sampra
Ranch Hand
Posts: 70
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Jaikiran Pai
Marshal
Pie
Posts: 10444
227
IntelliJ IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic