In my recent project i have to create a user who can be assigned multiple roles. The class structure looks as follows. In my UserAccount class the @ManyToMany relationship looks like as follows,

@ManyToMany@JoinTable(name="USER_ROLE",joinColumns=@JoinColumn(name="USER_NAME",referencedColumnName="USER_NAME"),inverseJoinColumns=@JoinColumn(name="SITE_ROLE_ID",referencedColumnName="ID"))
private List<siterole> userRoles=new Vector();
public UserAccount() {}

In SiteRole class the @ManyToMany relationship looks like as follows,

@ManyToMany@JoinTable(name="USER_ROLE",joinColumns=@JoinColumn(name="SITE_ROLE_ID",referencedColumnName="ID"),inverseJoinColumns=@JoinColumn(name="USER_NAME",referencedColumnName="USER_NAME"))
private List<useraccount> users =new Vector();

In the UserRole (mapped to join table) attributes are as follows,

@EmbeddedIdprotected UserRolePK userRolePK;
@JoinColumn(name = "SITE_ROLE_ID", referencedColumnName = "ID", insertable = false, updatable = false)
@ManyToOneprivate SiteRole siteRole;
@JoinColumn(name = "USER_NAME", referencedColumnName = "USER_NAME", insertable = false, updatable = false)
@ManyToOneprivate UserAccount userAccount;

The UserRolePK class attributes are as follows

@Embeddablepublic class UserRolePK implements Serializable {@Column(name = "SITE_ROLE_ID", nullable = false)private long siteRoleId;@Column(name = "USER_NAME")private String userName;

The UserRolePK class is needed as the UserRole table has composite key ( remember ?? the ejb days writing the PKClass).Hmm..the title goes like Seam Framework …., what seam has anything to do with this?Well seam makes the user creation with multiple roles easy using seam tags like selectManyCheckboxes as explained here.Moreover jpaidentitystore in seam framework helps in declaring the user-class and role-class inside of components class as explained here.