User.kt 1007 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package com.server.alb.models
  2. import jakarta.persistence.*
  3. @Entity
  4. @Table(name = "users")
  5. class User() {
  6. @Id
  7. @Column(name = "user_id")
  8. @GeneratedValue(strategy = GenerationType.IDENTITY)
  9. var id: Long = 0
  10. var username: String = ""
  11. var password: String = ""
  12. var isEnabled = false
  13. @ManyToMany(cascade = [CascadeType.ALL], fetch = FetchType.EAGER)
  14. @JoinTable(
  15. name = "users_roles",
  16. joinColumns = [JoinColumn(name = "user_id")],
  17. inverseJoinColumns = [JoinColumn(name = "role_id")]
  18. )
  19. var roles: Set<Role> = HashSet()
  20. @OneToMany(mappedBy = "qcId", cascade = [CascadeType.ALL], orphanRemoval = true)
  21. var qcId: List<ListBug> = mutableListOf()
  22. @OneToMany(mappedBy = "proId", cascade = [CascadeType.ALL], orphanRemoval = true)
  23. var proId: List<ListBug> = mutableListOf()
  24. @Transient
  25. var roleName: Role? = null
  26. @PostLoad
  27. fun onLoad() {
  28. for (role in roles) {
  29. roleName = role
  30. }
  31. }
  32. }