User.java 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package com.moekr.moocoder.data.entity;
  2. import com.moekr.moocoder.util.enums.UserRole;
  3. import lombok.Data;
  4. import lombok.EqualsAndHashCode;
  5. import lombok.ToString;
  6. import org.hibernate.annotations.LazyCollection;
  7. import org.hibernate.annotations.LazyCollectionOption;
  8. import org.springframework.data.annotation.CreatedDate;
  9. import org.springframework.data.jpa.domain.support.AuditingEntityListener;
  10. import javax.persistence.*;
  11. import java.time.LocalDateTime;
  12. import java.util.HashSet;
  13. import java.util.Set;
  14. @Data
  15. @EqualsAndHashCode(exclude = {"problemSet", "examSet", "resultSet", "courses"})
  16. @ToString(exclude = {"problemSet", "examSet", "resultSet","courses"})
  17. @Entity
  18. @Table(name = "ENTITY_USER", indexes = {@Index(columnList = "username"), @Index(columnList = "email")})
  19. @EntityListeners(AuditingEntityListener.class)
  20. public class User {
  21. @Id
  22. @Column(name = "id")
  23. private Integer id;
  24. @Basic
  25. @Column(name = "username", nullable = false)
  26. private String username;
  27. @Basic
  28. @Column(name = "password", nullable = false)
  29. private String password;
  30. @Basic
  31. @Column(name = "email", nullable = false)
  32. private String email;
  33. @Basic
  34. @Column(name = "namespace", nullable = false)
  35. private Integer namespace;
  36. @Basic
  37. @Column(name = "token", nullable = false)
  38. private String token;
  39. @Enumerated(EnumType.STRING)
  40. @Column(name = "role", nullable = false)
  41. private UserRole role;
  42. @Enumerated(EnumType.STRING)
  43. @Column(name = "phone")
  44. private String phone;
  45. @Basic
  46. @Column(name = "created_at", nullable = false)
  47. @CreatedDate
  48. private LocalDateTime createdAt;
  49. @OneToMany(targetEntity = Problem.class, mappedBy = "creator", cascade = CascadeType.REMOVE)
  50. @LazyCollection(LazyCollectionOption.EXTRA)
  51. private Set<Problem> problemSet = new HashSet<>();
  52. @OneToMany(targetEntity = Exam.class, mappedBy = "creator", cascade = CascadeType.REMOVE)
  53. @LazyCollection(LazyCollectionOption.EXTRA)
  54. private Set<Exam> examSet = new HashSet<>();
  55. @OneToMany(targetEntity = Result.class, mappedBy = "owner", cascade = CascadeType.REMOVE)
  56. @LazyCollection(LazyCollectionOption.EXTRA)
  57. private Set<Result> resultSet = new HashSet<>();
  58. @ManyToMany
  59. @JoinTable(name="STUDENT_COURSE", joinColumns = @JoinColumn(name = "student", referencedColumnName = "id"),
  60. inverseJoinColumns = @JoinColumn(name = "course", referencedColumnName = "id"))
  61. private Set<Course> courses = new HashSet<>();
  62. }