Hi

I've got the following setup. A user entity and a role entity. The user has
a collection of Role, annotated like this


public class User{

        ....
       @ManyToMany(cascade = CascadeType.ALL)
         private Collection<Role> roles = new HashSet<Role>();

}

public Role {
       private int role_id;

    @Column(name = "role")
    private Roles role;
}

Where Roles is a enum, with the possible roles. So first of all is this the
correct setup if I also want to have many users been able to have the same
role?

e.g User 1, Role:Admin,User,Tester
       User2, Role:Admin,Tester

So when persisting a new user the role is also persists the Role object even
if there is one from before. so in the example above the Admin and tester
role would be inserted twice, and I of course want them to be inserted just
once. Is there a way to do this? Should  annotate the Role entity with
something more?

cheers, Håkon


-- 
Håkon Sagehaug, Software Developer
Parallab, Bergen Center for Computational Science (BCCS)
UNIFOB AS (University of Bergen Research Company)

Reply via email to