I am using Hibernate 3.2.1 and hibernate-annotations 3.2.1.
I am having Three tables namely
1. User 2.Role 3.User_Role_Map
In my User pojo , i am having a property java.util.Set<Role> roles for roles assosiated to the user. And in my Role pojo, i have java.util.Set<User> users property for bidirectional mapping.
I donot have any pojo for User_Role_Map table.
when i query for getUser(id), it returns me User object with all mapped roles. But when i modify the roles and save the user, modified roles are not updated in the User_Role_Map table.
------- User.java ------
@ManyToMany(targetEntity=org.appfuse.model.Role.class,
fetch = FetchType.EAGER,
cascade = {CascadeType.PERSIST,CascadeType.MERGE})
@JoinTable(
name="user_role_map",
joinColumns = { @JoinColumn( name="user_id") },
inverseJoinColumns = @JoinColumn( name="role_id")
)
public Set<Role> getRoles() {
return roles;
}
-------- Role.java -------
@ManyToMany(fetch = FetchType.EAGER,
cascade = {CascadeType.PERSIST,CascadeType.MERGE},
targetEntity = org.appfuse.model.User.class,
mappedBy = "roles")
public Set<User> getUsers() {
return users;
}
can any one help me in this issue?
|