One user corresponds to one role. I use method userBean.setRole(role) to assign a role to a user, it works fine. But when I use same method to change an existing user's role, there will have two records appear in the role table as the result. The previous record(which suppose should be deleted) is still there with the user_id column was set to null and a new record added correctly.
Could anyone give a hint?
it also happens in one-more relationship specially.
This is the way it should work. You should remove the role by invoking remove() on it.