@Entity
@Table(name = "users")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(name = "login")
private String login;
@Column(name = "name")
private String name;
@Column(name = "lastname")
private String lastname;
@Column(name = "avatar")
private String avatar;
@Column(name = "email")
private String email;
@Column(name = "password")
private String password;
@Column(name = "flag")
private String flag;
@Column(name = "key_token")
private String key_token;
@Transient
private String confirmPassword;
@ManyToMany
@JoinTable(name = "user_roles", joinColumns = @JoinColumn(name = "user_id"),
inverseJoinColumns = @JoinColumn(name = "role_id"))
Set<Role> roles;
public User() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public String getAvatar() {
return avatar;
}
public void setAvatar(String avatar) {
this.avatar = avatar;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getConfirmPassword() {
return confirmPassword;
}
public void setConfirmPassword(String confirmPassword) {
this.confirmPassword = confirmPassword;
}
public Set<Role> getRoles() {
return roles;
}
public void setRoles(Set<Role> roles) {
this.roles = roles;
}
public String getFlag() {
return flag;
}
public void setFlag(String flag) {
this.flag = flag;
}
public String getKey_token() {
return key_token;
}
public void setKey_token(String key_token) {
this.key_token = key_token;
}
}
это POJO User, вопрос в том обязательно ли делать ManyToMany, когда роль для пользователя одна?