| Author |
Delete/update associations question
|
Naveen Sampra
Ranch Hand
Joined: Jun 11, 2003
Posts: 70
|
|
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
Sheriff
Joined: Jul 11, 2001
Posts: 15040
|
|
|
I think I'll shimmy this on over to our ORM forum where folk talk about Hibernate on a regular basis.
|
My Blog | DZone Articles
|
 |
Jaikiran Pai
Saloon Keeper
Joined: Jul 20, 2005
Posts: 6718
|
|
Change your User hbm to contain: And the code: Also, have a look at the "Cascading lifecycle" section at Hibernate reference - Parent child example
|
[My Blog] [JavaRanch Journal]
|
 |
Naveen Sampra
Ranch Hand
Joined: Jun 11, 2003
Posts: 70
|
|
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.
|
 |
 |
|
|
subject: Delete/update associations question
|
|
|