Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package th.co.geniustree.dental.model; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonManagedReference; import java.io.Serializable; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Objects; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; import javax.persistence.ManyToMany; import javax.persistence.OneToMany; import org.hibernate.validator.constraints.Email; import org.hibernate.validator.constraints.NotBlank; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.userdetails.UserDetails; import th.co.geniustree.dental.validator.EmployeeEmailUnique; /** * * @author Best */ @Entity @Inheritance(strategy = InheritanceType.JOINED) public class Employee implements Serializable, UserDetails { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Integer id; // @EmployeeEmailUnique() @Column(name = "EMAIL", nullable = false) @NotBlank(message = "??? ") @Email(message = "example@example.com") private String email; @Column(name = "PASSWORD", nullable = false) @NotBlank(message = "???") private String password; @Column(name = "NAME_TH", nullable = false) @NotBlank(message = "??? ") private String nameTh; private String type; private boolean enable = true; @ManyToMany @Column(name = "ROLES") private List<Authority> roles; public String getNameTh() { return nameTh; } public void setNameTh(String nameTh) { this.nameTh = nameTh; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } 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 getType() { return type; } public void setType(String type) { this.type = type; } public boolean isEnable() { return enable; } public void setEnable(boolean enable) { this.enable = enable; } public List<Authority> getRoles() { return roles; } public void setRoles(List<Authority> roles) { this.roles = roles; } @Override public int hashCode() { int hash = 3; hash = 29 * hash + Objects.hashCode(this.id); return hash; } @Override public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final Employee other = (Employee) obj; if (!Objects.equals(this.id, other.id)) { return false; } return true; } @Override public Collection<? extends GrantedAuthority> getAuthorities() { // return roles; return Collections.emptySet(); } @Override public String getUsername() { return email; } @Override public boolean isAccountNonExpired() { return true; } @Override public boolean isAccountNonLocked() { return true; } @Override public boolean isCredentialsNonExpired() { return true; } @Override public boolean isEnabled() { return enable; } }