Advertisement
Guest User

Untitled

a guest
Jan 5th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. package entities;
  2.  
  3. import entities.UserGroup.GROUP;
  4. import java.io.Serializable;
  5. import javax.persistence.CascadeType;
  6. import javax.persistence.Column;
  7. import javax.persistence.Entity;
  8. import javax.persistence.FetchType;
  9. import javax.persistence.Id;
  10. import javax.persistence.Inheritance;
  11. import javax.persistence.InheritanceType;
  12. import javax.persistence.NamedQuery;
  13. import javax.persistence.OneToOne;
  14. import javax.persistence.Table;
  15. import util.Security;
  16.  
  17. @Entity
  18. @Table(name = "USERS")
  19. @Inheritance(strategy = InheritanceType.JOINED)
  20. @NamedQuery(name = "getAllUsers", query = "SELECT u FROM User u")
  21. public class User implements Serializable {
  22.  
  23. @Id
  24. protected String username;
  25.  
  26. @Column(nullable = false)
  27. protected String password;
  28.  
  29. @Column(nullable = false)
  30. protected String name;
  31.  
  32. @Column(nullable = false)
  33. protected String email;
  34.  
  35. @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "user")
  36. protected UserGroup group;
  37.  
  38. protected User() {
  39.  
  40. }
  41. public User(String username, String password, String name, String email) {
  42. this.username = username;
  43. this.password = Security.hashPassword(password);
  44. this.group = new UserGroup(GROUP.Student, this);
  45. this.name = name;
  46. this.email = email;
  47. }
  48.  
  49.  
  50. protected User(String username, String password, GROUP group, String name, String email) {
  51. this.username = username;
  52. this.password = Security.hashPassword(password);
  53. this.group = new UserGroup(group, this);
  54. this.name = name;
  55. this.email = email;
  56. }
  57.  
  58. public String getUsername() {
  59. return username;
  60. }
  61.  
  62. public void setUsername(String userName) {
  63. this.username = userName;
  64. }
  65.  
  66. public String getPassword() {
  67. return password;
  68. }
  69.  
  70. public void setPassword(String password) {
  71. this.password = password;
  72. }
  73.  
  74. public String getName() {
  75. return name;
  76. }
  77.  
  78. public void setName(String name) {
  79. this.name = name;
  80. }
  81.  
  82. public String getEmail() {
  83. return email;
  84. }
  85.  
  86. public void setEmail(String email) {
  87. this.email = email;
  88. }
  89.  
  90. public UserGroup getGroup() {
  91. return group;
  92. }
  93.  
  94. public void setGroup(UserGroup group) {
  95. this.group = group;
  96. }
  97.  
  98.  
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement