This content has been marked as final.
Show 3 replies
-
1. Re: Foreign key reference with cascading delete
wolfgangknauf Oct 19, 2006 6:06 AM (in response to jbr)Hi Juergen,
In your entity "ListEntry" the cascade should/might look like this:@OneToMany(cascade={CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH}) User getUser(){...
If you specifiy "REMOVE" then the user is deleted if the list entry is removed.
Best regards
Wolfgang -
2. Re: Foreign key reference with cascading delete
jbr Oct 19, 2006 10:14 AM (in response to jbr)Hi Wolfgang,
thanks for your help. I tried your suggestion. You are right as far as the user would survive the remove of a listEntry. But with this configuration i can't delete a user before all referencing listEntries are removed.
In terms of ER-Modelling it creates something like this:table user(String id, String name, ...) table listEntry(String id, String userId references user.id, String listId references list.id on delete cascade) table list(String id, String name)
But what I need is:table user(String id, String name, ...) table listEntry(String id, String userId references user.id on delete cascade, String listId references list.id on delete cascade) table list(String id, String name)
That's not exactly what i wanted, as i still need to cleanup the listentries manually before i can delete the user.
Have u successfully implemented something like that before?
Best Regards
Juergen -
3. Re: Foreign key reference with cascading delete
wolfgangknauf Oct 20, 2006 7:11 AM (in response to jbr)Hi Juergen,
you should change the relation from List to User to a bidirectional one. Something like this:
@OneToMany(cascade=CascadeType.REMOVE)
List getLists(){
...
}
This way, if you delete a user, all Lists are deleted, and also all ListEntries.
Hope this helps
Wolfgang