Advertisement
Guest User

Untitled

a guest
Jun 5th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.41 KB | None | 0 0
  1. package ua.samuliak.messenger.entity;
  2.  
  3. import org.hibernate.annotations.GenericGenerator;
  4.  
  5. import javax.persistence.*;
  6. import java.util.HashSet;
  7. import java.util.Set;
  8.  
  9. @Entity
  10. @Table(name = ""user"")
  11. public class User {
  12.  
  13. @Id
  14. @GeneratedValue(generator = "increment")
  15. @GenericGenerator(name = "increment", strategy = "increment")
  16. private Long id;
  17.  
  18. @Column(name = "id_room")
  19. private Long room;
  20.  
  21. @Column(nullable = false, length = 20)
  22. private String login;
  23.  
  24. @Column(nullable = false, length = 20)
  25. private String password;
  26.  
  27. @Column(length = 2)
  28. private String country;
  29.  
  30. @Column(length = 2)
  31. private Integer age;
  32.  
  33. @Column(length = 25)
  34. private String occupation;
  35.  
  36. @OneToMany(mappedBy = "user")
  37. private Set<Room> rooms = new HashSet<Room>();
  38.  
  39. @OneToMany(mappedBy = "user_mes")
  40. private Set<Message> messages = new HashSet<Message>();
  41.  
  42.  
  43. public User() {}
  44.  
  45. public User(String login, String password, String country) {
  46. this.login = login;
  47. this.password = password;
  48. this.country = country;
  49. }
  50.  
  51. public Long getId() {
  52. return id;
  53. }
  54.  
  55. public void setId(Long id) {
  56. this.id = id;
  57. }
  58.  
  59. public Long getRoom() {
  60. return room;
  61. }
  62.  
  63. public void setRoom(Long room) {
  64. this.room = room;
  65. }
  66.  
  67. public String getLogin() {
  68. return login;
  69. }
  70.  
  71. public void setLogin(String login) {
  72. this.login = login;
  73. }
  74.  
  75. public String getPassword() {
  76. return password;
  77. }
  78.  
  79. public void setPassword(String password) {
  80. this.password = password;
  81. }
  82.  
  83. public String getCountry() {
  84. return country;
  85. }
  86.  
  87. public void setCountry(String country) {
  88. this.country = country;
  89. }
  90.  
  91. public Integer getAge() {
  92. return age;
  93. }
  94.  
  95. public void setAge(Integer age) {
  96. this.age = age;
  97. }
  98.  
  99. public String getOccupation() {
  100. return occupation;
  101. }
  102.  
  103. public void setOccupation(String occupation) {
  104. this.occupation = occupation;
  105. }
  106.  
  107. // public Set<Room> getRooms() {
  108. // return rooms;
  109. // }
  110. //
  111. // public void setRooms(Set<Room> rooms) {
  112. // this.rooms = rooms;
  113. // }
  114. }
  115.  
  116. package ua.samuliak.messenger.entity;
  117.  
  118. import org.hibernate.annotations.GenericGenerator;
  119.  
  120. import javax.persistence.*;
  121. import java.util.HashSet;
  122. import java.util.Set;
  123.  
  124. @Entity
  125. @Table(name = "room")
  126. public class Room {
  127.  
  128. @Id
  129. @GeneratedValue(generator = "increment")
  130. @GenericGenerator(name = "increment", strategy = "increment")
  131. private Long id;
  132.  
  133. @Column(nullable = false, length = 30)
  134. private String title;
  135.  
  136. @ManyToOne
  137. @JoinColumn(name = "user_id")
  138. private User user;
  139.  
  140. @OneToMany(mappedBy = "room")
  141. private Set<Message> messages = new HashSet<Message>();
  142.  
  143.  
  144.  
  145. public Room() {}
  146.  
  147. public Room(String title, User user) {
  148. this.user = user;
  149. this.title = title;
  150. }
  151.  
  152. public Long getId() {
  153. return id;
  154. }
  155.  
  156. public void setId(Long id) {
  157. this.id = id;
  158. }
  159.  
  160. public String getTitle() {
  161. return title;
  162. }
  163.  
  164. public void setTitle(String title) {
  165. this.title = title;
  166. }
  167.  
  168. public User getUser() {
  169. return user;
  170. }
  171.  
  172. public void setUser(User user) {
  173. this.user = user;
  174. }
  175. }
  176.  
  177. package ua.samuliak.messenger.entity;
  178.  
  179. import org.hibernate.annotations.GenericGenerator;
  180.  
  181. import javax.persistence.*;
  182.  
  183. @Entity
  184. @Table(name = "message")
  185. public class Message {
  186.  
  187. @Id
  188. @GeneratedValue(generator = "increment")
  189. @GenericGenerator(name = "increment", strategy = "increment")
  190. private Long id;
  191.  
  192. @ManyToOne
  193. @JoinColumn(name = "room_id")
  194. private Room room;
  195.  
  196. @ManyToOne
  197. @JoinColumn(name = "user_id")
  198. private Room user_mes;
  199.  
  200. @Column(nullable = false)
  201. private String value;
  202.  
  203.  
  204. public Message() {}
  205.  
  206. public Message(Room room, String value) {
  207. this.room = room;
  208. this.value = value;
  209. }
  210.  
  211. public Long getId() {
  212. return id;
  213. }
  214.  
  215. public void setId(Long id) {
  216. this.id = id;
  217. }
  218.  
  219. public Room getRoom() {
  220. return room;
  221. }
  222.  
  223. public void setRoom(Room room) {
  224. this.room = room;
  225. }
  226.  
  227. public Room getUser_mes() {
  228. return user_mes;
  229. }
  230.  
  231. public void setUser_mes(Room user_mes) {
  232. this.user_mes = user_mes;
  233. }
  234.  
  235. public String getValue() {
  236. return value;
  237. }
  238.  
  239. public void setValue(String value) {
  240. this.value = value;
  241. }
  242. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement