Advertisement
Guest User

Untitled

a guest
Apr 1st, 2021
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. package coffeeshop.entity;
  2.  
  3. import java.io.Serializable;
  4. import java.math.BigDecimal;
  5. import java.util.List;
  6. import javax.persistence.Basic;
  7. import javax.persistence.Column;
  8. import javax.persistence.Entity;
  9. import javax.persistence.GeneratedValue;
  10. import javax.persistence.GenerationType;
  11. import javax.persistence.Id;
  12. import javax.persistence.JoinColumn;
  13. import javax.persistence.ManyToMany;
  14. import javax.persistence.ManyToOne;
  15. import javax.persistence.NamedQueries;
  16. import javax.persistence.NamedQuery;
  17. import javax.persistence.Table;
  18. import javax.validation.constraints.Size;
  19. import javax.xml.bind.annotation.XmlRootElement;
  20.  
  21. @Entity
  22. @Table(name = "category")
  23. @XmlRootElement
  24. @NamedQueries({
  25. @NamedQuery(name = "Category.findAll", query = "SELECT c FROM Category c")
  26. , @NamedQuery(name = "Category.findById", query = "SELECT c FROM Category c WHERE c.id = :id")
  27. , @NamedQuery(name = "Category.findByCname", query = "SELECT c FROM Category c WHERE c.cname = :cname")
  28. , @NamedQuery(name = "Category.findByCprice", query = "SELECT c FROM Category c WHERE c.cprice = :cprice")})
  29. public class Category implements Serializable, Comparable {
  30.  
  31. private static final long serialVersionUID = 1L;
  32. @Id
  33. @GeneratedValue(strategy = GenerationType.IDENTITY)
  34. @Basic(optional = false)
  35. @Column(name = "id")
  36. private Integer id;
  37. @Size(max = 45)
  38. @Column(name = "cname")
  39. private String cname;
  40. // @Max(value=?) @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
  41. @Column(name = "cprice")
  42. private BigDecimal cprice;
  43. @JoinColumn(name = "cat_b_id", referencedColumnName = "id")
  44. @ManyToOne(optional = false)
  45. private CatB catBId;
  46. @ManyToMany(mappedBy = "categories")
  47. private List<OrderDetails> orderDetails;
  48.  
  49. public Category() {
  50. }
  51.  
  52. public Category(Integer id) {
  53. this.id = id;
  54. }
  55.  
  56. public Integer getId() {
  57. return id;
  58. }
  59.  
  60. public void setId(Integer id) {
  61. this.id = id;
  62. }
  63.  
  64. public String getCname() {
  65. return cname;
  66. }
  67.  
  68. public void setCname(String cname) {
  69. this.cname = cname;
  70. }
  71.  
  72. public BigDecimal getCprice() {
  73. return cprice;
  74. }
  75.  
  76. public void setCprice(BigDecimal cprice) {
  77. this.cprice = cprice;
  78. }
  79.  
  80. public CatB getCatBId() {
  81. return catBId;
  82. }
  83.  
  84. public void setCatBId(CatB catBId) {
  85. this.catBId = catBId;
  86. }
  87.  
  88. public List<OrderDetails> getOrderDetails() {
  89. return orderDetails;
  90. }
  91.  
  92. public void setOrderDetails(List<OrderDetails> orderDetails) {
  93. this.orderDetails = orderDetails;
  94. }
  95.  
  96. @Override
  97. public int hashCode() {
  98. int hash = 0;
  99. hash += (id != null ? id.hashCode() : 0);
  100. return hash;
  101. }
  102.  
  103. @Override
  104. public boolean equals(Object object) {
  105. // TODO: Warning - this method won't work in the case the id fields are not set
  106. if (!(object instanceof Category)) {
  107. return false;
  108. }
  109. Category other = (Category) object;
  110. if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
  111. return false;
  112. }
  113. return true;
  114. }
  115.  
  116. @Override
  117. public String toString() {
  118. return cname;
  119. }
  120.  
  121. @Override
  122. public int compareTo(Object o) {
  123. return this.id - ((Category) o).id;
  124. }
  125.  
  126. }
  127.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement