Advertisement
Guest User

Untitled

a guest
Apr 1st, 2021
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. package coffeeshop.entity;
  2.  
  3. import java.io.Serializable;
  4. import java.util.List;
  5. import java.util.Objects;
  6. import javax.persistence.Basic;
  7. import javax.persistence.CascadeType;
  8. import javax.persistence.Column;
  9. import javax.persistence.Entity;
  10. import javax.persistence.FetchType;
  11. import javax.persistence.GeneratedValue;
  12. import javax.persistence.GenerationType;
  13. import javax.persistence.Id;
  14. import javax.persistence.JoinColumn;
  15. import javax.persistence.JoinTable;
  16. import javax.persistence.ManyToMany;
  17. import javax.persistence.ManyToOne;
  18. import javax.persistence.NamedQueries;
  19. import javax.persistence.NamedQuery;
  20. import javax.persistence.Table;
  21. import javax.xml.bind.annotation.XmlRootElement;
  22.  
  23. @Entity
  24. @Table(name = "order_details")
  25. @XmlRootElement
  26. @NamedQueries({
  27. @NamedQuery(name = "OrderDetails.findAll", query = "SELECT o FROM OrderDetails o")
  28. , @NamedQuery(name = "OrderDetails.findById", query = "SELECT o FROM OrderDetails o WHERE o.id = :id")
  29. , @NamedQuery(name = "OrderDetails.findByQuantity", query = "SELECT o FROM OrderDetails o WHERE o.quantity = :quantity")})
  30. public class OrderDetails implements Serializable {
  31.  
  32.  
  33. private static final long serialVersionUID = 1L;
  34. @Id
  35. @GeneratedValue(strategy = GenerationType.IDENTITY)
  36. @Basic(optional = false)
  37. @Column(name = "id")
  38. private Integer id;
  39. @JoinColumn(name = "product_id", referencedColumnName = "id")
  40. @ManyToOne(fetch = FetchType.LAZY)
  41. private Product product;
  42. @JoinColumn(name = "order_id", referencedColumnName = "id")
  43. @ManyToOne(fetch = FetchType.LAZY)
  44. private Orders orders;
  45. @Column(name = "quantity")
  46. private Integer quantity;
  47. @ManyToMany(cascade = CascadeType.ALL)
  48. @JoinTable(name = "details_categories",
  49. joinColumns = {
  50. @JoinColumn(name = "order_details_id", referencedColumnName = "id")},
  51. inverseJoinColumns = {
  52. @JoinColumn(name = "category_id", referencedColumnName = "id")})
  53. private List<Category> categories;
  54.  
  55. @Column(name = "unitprice", precision=4, scale=2)
  56. private double unitPrice;
  57.  
  58. public OrderDetails() {
  59. }
  60.  
  61. public OrderDetails(Integer id) {
  62. this.id = id;
  63. }
  64.  
  65. public Integer getId() {
  66. return id;
  67. }
  68.  
  69. public void setId(Integer id) {
  70. this.id = id;
  71. }
  72.  
  73. public Product getProduct() {
  74. return product;
  75. }
  76.  
  77. public void setProduct(Product product) {
  78. this.product = product;
  79. }
  80.  
  81. public Orders getOrder() {
  82. return orders;
  83. }
  84.  
  85. public void setOrder(Orders orders) {
  86. this.orders = orders;
  87. }
  88.  
  89. public Integer getQuantity() {
  90. return quantity;
  91. }
  92.  
  93. public void setQuantity(Integer quantity) {
  94. this.quantity = quantity;
  95. }
  96.  
  97. // @XmlTransient
  98. public List<Category> getCategories() {
  99. return categories;
  100. }
  101.  
  102. public void setCategories(List<Category> categories) {
  103. this.categories = categories;
  104. }
  105.  
  106. public double getUnitPrice() {
  107. return unitPrice;
  108. }
  109.  
  110. public void setUnitPrice(double unitPrice) {
  111. this.unitPrice = unitPrice;
  112. }
  113.  
  114. @Override
  115. public int hashCode() {
  116. int hash = 0;
  117. hash += (id != null ? id.hashCode() : 0);
  118. return hash;
  119. }
  120.  
  121. @Override
  122. public boolean equals(Object obj) {
  123. if (this == obj) {
  124. return true;
  125. }
  126. if (obj == null) {
  127. return false;
  128. }
  129. if (getClass() != obj.getClass()) {
  130. return false;
  131. }
  132. final OrderDetails other = (OrderDetails) obj;
  133. if (!Objects.equals(this.product, other.product)) {
  134. return false;
  135. }
  136. if (!Objects.equals(this.categories, other.categories)) {
  137. return false;
  138. }
  139. return true;
  140. }
  141.  
  142.  
  143. @Override
  144. public String toString() {
  145. return "coffeeshop.entity.OrderDetails[ id=" + id + " ]";
  146. }
  147. }
  148.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement