/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package veolia.core.entities; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinTable; import javax.persistence.ManyToMany; import javax.persistence.Table; import org.eclipse.persistence.annotations.CascadeOnDelete; import org.hibernate.validator.constraints.Email; import org.hibernate.validator.constraints.NotEmpty; /** * * @author Toto-Works */ @Entity @Table(name="core_user") public class User implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @NotEmpty(message="Champ email obligatoire") @Email(message="Doit ĂȘtre un email valide") @Column(nullable = false, unique=true) private String email; @NotEmpty(message="Champ mot de passe obligatoire") @Column(nullable=false) private String password; @ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL) @JoinTable(name="users_groups") @CascadeOnDelete private List groups; @ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL) @JoinTable(name="users_permissions") @CascadeOnDelete private List permissions = new ArrayList<>(); public Long getId() { return id; } public void setId(Long id) { this.id = id; } /** * @return the email */ public String getEmail() { return email; } /** * @param email the email to set */ public void setEmail(String email) { this.email = email; } /** * @return the password */ public String getPassword() { return password; } /** * @param password the password to set */ public void setPassword(String password) { this.password = password; } /** * @return the goups */ public List getGroups() { return groups; } /** * @param groups the goups to set */ public void setGroups(List groups) { this.setGroups(groups); } /** * @return the permissions */ public List getPermissions() { return permissions; } /** * @param permissions the permissions to set */ public void setPermissions(List permissions) { this.setPermissions(permissions); } @Override public int hashCode() { int hash = 0; hash += (id != null ? id.hashCode() : 0); return hash; } @Override public boolean equals(Object object) { // TODO: Warning - this method won't work in the case the id fields are not set if (!(object instanceof User)) { return false; } User other = (User) object; return (this.id != null || other.id == null) && (this.id == null || this.id.equals(other.id)); } @Override public String toString() { return "veolia.core.entities.User[ id=" + id + " ]"; } }