Guest User

Untitled

a guest
Nov 21st, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.76 KB | None | 0 0
  1. package com.testbackfortheinterview.interview.entity;
  2.  
  3. import com.testbackfortheinterview.interview.entity.enums.TypeDepartment;
  4.  
  5. import javax.persistence.*;
  6. import java.util.List;
  7.  
  8. @Entity
  9. @Table(name = "DEPARTMENT")
  10. public class Department {
  11.  
  12. @Id
  13. @GeneratedValue(strategy = GenerationType.AUTO)
  14. @Column(name = "ID")
  15. private long id;
  16.  
  17. @Column(unique = true, nullable = false)
  18. private String name;
  19.  
  20. private TypeDepartment department;
  21.  
  22. // здесь неправильный именование для сущности
  23. @OneToMany(mappedBy = "furnitures")
  24. private List<Furniture> furnitureList;
  25.  
  26. @OneToMany(mappedBy = "orders")
  27. private List<Order> orderList;
  28.  
  29. @OneToMany(mappedBy = "masters")
  30. private List<Master> masterList;
  31.  
  32. public Department() {
  33. }
  34.  
  35. public Department(final TypeDepartment department) {
  36. this.department = department;
  37. }
  38.  
  39. public Department(final long id, final String name, final TypeDepartment department, final List<Furniture> furnitureList, final List<Order> orderList, final List<Master> masterListp) {
  40. this.id = id;
  41. this.name = name;
  42. this.department = department;
  43. this.furnitureList = furnitureList;
  44. this.orderList = orderList;
  45. this.masterList = masterListp;
  46. }
  47.  
  48. public long getId() {
  49. return id;
  50. }
  51.  
  52. public void setId(final long id) {
  53. this.id = id;
  54. }
  55.  
  56. public String getName() {
  57. return name;
  58. }
  59.  
  60. public void setName(final String name) {
  61. this.name = name;
  62. }
  63.  
  64. public TypeDepartment getDepartment() {
  65. return department;
  66. }
  67.  
  68. public void setDepartment(TypeDepartment department) {
  69. this.department = department;
  70. }
  71.  
  72. public List<Furniture> getFurnitureList() {
  73. return furnitureList;
  74. }
  75.  
  76. public void setFurnitureList(final List<Furniture> furnitureList) {
  77. this.furnitureList = furnitureList;
  78. }
  79.  
  80. public List<Order> getOrderList() {
  81. return orderList;
  82. }
  83.  
  84. public void setOrderList(final List<Order> orderList) {
  85. this.orderList = orderList;
  86. }
  87.  
  88. public List<Master> getMasterList() {
  89. return masterList;
  90. }
  91.  
  92. public void setMasterList(final List<Master> masterList) {
  93. this.masterList = masterList;
  94. }
  95.  
  96. @Override
  97. public boolean equals(final Object o) {
  98. if (this == o) return true;
  99. if (!(o instanceof Department)) return false;
  100.  
  101. Department that = (Department) o;
  102.  
  103. if (getId() != that.getId()) return false;
  104. if (getName() != null ? !getName().equals(that.getName()) : that.getName() != null) return false;
  105. if (getDepartment() != that.getDepartment()) return false;
  106. if (getFurnitureList() != null ? !getFurnitureList().equals(that.getFurnitureList()) : that.getFurnitureList() != null)
  107. return false;
  108. if (getOrderList() != null ? !getOrderList().equals(that.getOrderList()) : that.getOrderList() != null)
  109. return false;
  110. return getMasterList() != null ? getMasterList().equals(that.getMasterList()) : that.getMasterList() == null;
  111. }
  112.  
  113.  
  114. @Override
  115. public int hashCode() {
  116. int result = (int) (getId() ^ (getId() >>> 32));
  117. result = 31 * result + (getName() != null ? getName().hashCode() : 0);
  118. result = 31 * result + (getDepartment() != null ? getDepartment().hashCode() : 0);
  119. result = 31 * result + (getFurnitureList() != null ? getFurnitureList().hashCode() : 0);
  120. result = 31 * result + (getOrderList() != null ? getOrderList().hashCode() : 0);
  121. result = 31 * result + (getMasterList() != null ? getMasterList().hashCode() : 0);
  122. return result;
  123. }
  124.  
  125. @Override
  126. public String toString() {
  127. return "Department{" +
  128. "id=" + id +
  129. ", name='" + name + '\'' +
  130. ", department=" + department +
  131. ", furnitureList=" + furnitureList +
  132. ", orderList=" + orderList +
  133. ", masterList=" + masterList +
  134. '}';
  135. }
  136. }
  137.  
  138.  
  139. package com.testbackfortheinterview.interview.entity;
  140.  
  141. import com.testbackfortheinterview.interview.entity.enums.TypeDepartment;
  142. import com.testbackfortheinterview.interview.entity.enums.TypeofFurniture;
  143.  
  144. import javax.persistence.*;
  145.  
  146.  
  147. @Entity
  148. @Table(name = "FURNITURE")
  149. public class Furniture {
  150.  
  151. @Id
  152. @GeneratedValue(strategy = GenerationType.AUTO)
  153. @Column(name = "ID")
  154. private long id;
  155.  
  156. @Column(unique = true, nullable = false)
  157. private String name;
  158.  
  159. @ManyToOne
  160. @JoinColumn(name = "DEPARTMENT_ID", nullable = false)
  161. private Department department;
  162.  
  163. private TypeofFurniture typeofFurniture;
  164.  
  165. public Furniture() {
  166. }
  167.  
  168. public Furniture(final String name, final Department department, final TypeofFurniture typeofFurniture) {
  169. this.name = name;
  170. this.department = department;
  171. this.typeofFurniture = typeofFurniture;
  172. }
  173.  
  174. public long getId() {
  175. return id;
  176. }
  177.  
  178. public void setId(final long id) {
  179. this.id = id;
  180. }
  181.  
  182. public String getName() {
  183. return name;
  184. }
  185.  
  186. public void setName(final String name) {
  187. this.name = name;
  188. }
  189.  
  190. public Department getDepartment() {
  191. return department;
  192. }
  193.  
  194. public void setDepartment(final Department department) {
  195. this.department = department;
  196. }
  197.  
  198. public TypeofFurniture getTypeofFurniture() {
  199. return typeofFurniture;
  200. }
  201.  
  202. public void setTypeofFurniture(final TypeofFurniture typeofFurniture) {
  203. this.typeofFurniture = typeofFurniture;
  204. }
  205.  
  206. @Override
  207. public boolean equals(final Object o) {
  208. if (this == o) return true;
  209. if (!(o instanceof Furniture)) return false;
  210.  
  211. Furniture furniture = (Furniture) o;
  212.  
  213. if (getId() != furniture.getId()) return false;
  214. if (getName() != null ? !getName().equals(furniture.getName()) : furniture.getName() != null) return false;
  215. if (getDepartment() != null ? !getDepartment().equals(furniture.getDepartment()) : furniture.getDepartment() != null)
  216. return false;
  217. return getTypeofFurniture() == furniture.getTypeofFurniture();
  218. }
  219.  
  220. @Override
  221. public int hashCode() {
  222. int result = (int) (getId() ^ (getId() >>> 32));
  223. result = 31 * result + (getName() != null ? getName().hashCode() : 0);
  224. result = 31 * result + (getDepartment() != null ? getDepartment().hashCode() : 0);
  225. result = 31 * result + (getTypeofFurniture() != null ? getTypeofFurniture().hashCode() : 0);
  226. return result;
  227. }
  228.  
  229. @Override
  230. public String toString() {
  231. return "Furniture{" +
  232. "id=" + id +
  233. ", name='" + name + '\'' +
  234. ", department=" + department +
  235. ", typeofFurniture=" + typeofFurniture +
  236. '}';
  237. }
  238. }
Add Comment
Please, Sign In to add comment