DELETE FROM MY_USER_ROLE_TABLE WHERE id_role = ?; -- replace the question mark with the id of the role DELETE FROM MY_ROLE_TABLE WHERE id_role = ?;
996726 wrote:You're welcome, but after rp2048's response I do realize I misread your question a little bit. I would only do the 'remove all' trick in the user_role table. I was assuming you were talking about easily updating which roles a specific user has. You can't just delete roles themselves because they will likely still be in use by other users; referential integrity comes into play there.
Thank you gimbal2, i'll try to read about jdbc api and sql
ie : i have a user entry in user table with 3 roles , so 3 entries in role table and 3 entries in role_user table
now i map these entries into one java object User with List of role and i want to remove one role from the list
and update the database, i wonder if i should delete all entries in role and role_user table and insert the new
2 entries or there is another method by which i can remove only one entry
gimbal2 wrote:Nah.Tolls wrote:Ouch, cascaded deletes are like grenades dude ;)
See above then...though in this case I would go for a ON DELETE CASCADE, but that's just me.
Tolls wrote:Agreed, I use them when they make sense (more in a JPA/ORM environment though). But you'd have to take a gander in JPA forums to see people posting their models with cascades on EVERYTHING... copy/paste, copy/paste, copy/paste, I don't know what it implies but copy/paste...
People are simply too afraid to use them. It's a bit like the abuse of outer joins "in case I miss something".