content: package spring.security.model;
  
  import javax.persistence.*;
  import java.util.Collection;
  
  /**
   * @Created 29 / 04 / 2020 - 3:51 PM
   * @project SpringRegistor
   * @Author Hamdamboy
   */
  
  
  
  //@Table(uniqueContraints = @UniqueConstraint(columnNames = "email"))
  @Entity
  @Table(uniqueConstraints={@UniqueConstraint(columnNames={"email"})})
  public class User {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Long id;
  
      private String firstName;
      private String lastName;
      private String email;
      private String password;
  
  
  
      public void setId(Long id) {
          this.id = id;
      }
  
      public String getFirstName() {
          return firstName;
      }
  
      public void setFirstName(String firstName) {
          this.firstName = firstName;
      }
  
      public String getLastName() {
          return lastName;
      }
  
      public void setLastName(String lastName) {
          this.lastName = lastName;
      }
  
      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 Collection<Role> getRoles() {
          return roles;
      }
  
  
      public void setRoles(Collection<Role> roles) {
          this.roles = roles;
      }
  
      @ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
      @JoinTable(
              name = "users_roles",
              joinColumns = @JoinColumn(
                      name = "user_id", referencedColumnName = "id"),
              inverseJoinColumns = @JoinColumn(
                      name = "role_id", referencedColumnName = "id"))
  
      private Collection<Role> roles;
  
      public User() {
      }
  
      public User(String firstName, String lastName, String email, String password) {
          this.firstName = firstName;
          this.lastName = lastName;
          this.email = email;
          this.password = password;
      }
  
      public User(String firstName, String lastName, String email, String password, Collection<Role> roles) {
          this.firstName = firstName;
          this.lastName = lastName;
          this.email = email;
          this.password = password;
          this.roles = roles;
      }
  
      public Long getId() {
          return id;
      }
  
      @Override
      public String toString() {
          return "User{" +
                  "id=" + id +
                  ", firstName='" + firstName + '\'' +
                  ", lastName='" + lastName + '\'' +
                  ", email='" + email + '\'' +
                  ", password='" + "admin123" + '\'' +
                  ", roles=" + roles +
                  '}';
      }
  }
  