Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package coffeeshop.entity;
- import java.io.Serializable;
- import java.math.BigDecimal;
- import java.util.List;
- import javax.persistence.Basic;
- import javax.persistence.Column;
- import javax.persistence.Entity;
- import javax.persistence.GeneratedValue;
- import javax.persistence.GenerationType;
- import javax.persistence.Id;
- import javax.persistence.JoinColumn;
- import javax.persistence.ManyToMany;
- import javax.persistence.ManyToOne;
- import javax.persistence.NamedQueries;
- import javax.persistence.NamedQuery;
- import javax.persistence.Table;
- import javax.validation.constraints.Size;
- import javax.xml.bind.annotation.XmlRootElement;
- @Entity
- @Table(name = "category")
- @XmlRootElement
- @NamedQueries({
- @NamedQuery(name = "Category.findAll", query = "SELECT c FROM Category c")
- , @NamedQuery(name = "Category.findById", query = "SELECT c FROM Category c WHERE c.id = :id")
- , @NamedQuery(name = "Category.findByCname", query = "SELECT c FROM Category c WHERE c.cname = :cname")
- , @NamedQuery(name = "Category.findByCprice", query = "SELECT c FROM Category c WHERE c.cprice = :cprice")})
- public class Category implements Serializable, Comparable {
- private static final long serialVersionUID = 1L;
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- @Basic(optional = false)
- @Column(name = "id")
- private Integer id;
- @Size(max = 45)
- @Column(name = "cname")
- private String cname;
- // @Max(value=?) @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
- @Column(name = "cprice")
- private BigDecimal cprice;
- @JoinColumn(name = "cat_b_id", referencedColumnName = "id")
- @ManyToOne(optional = false)
- private CatB catBId;
- @ManyToMany(mappedBy = "categories")
- private List<OrderDetails> orderDetails;
- public Category() {
- }
- public Category(Integer id) {
- this.id = id;
- }
- public Integer getId() {
- return id;
- }
- public void setId(Integer id) {
- this.id = id;
- }
- public String getCname() {
- return cname;
- }
- public void setCname(String cname) {
- this.cname = cname;
- }
- public BigDecimal getCprice() {
- return cprice;
- }
- public void setCprice(BigDecimal cprice) {
- this.cprice = cprice;
- }
- public CatB getCatBId() {
- return catBId;
- }
- public void setCatBId(CatB catBId) {
- this.catBId = catBId;
- }
- public List<OrderDetails> getOrderDetails() {
- return orderDetails;
- }
- public void setOrderDetails(List<OrderDetails> orderDetails) {
- this.orderDetails = orderDetails;
- }
- @Override
- public int hashCode() {
- int hash = 0;
- hash += (id != null ? id.hashCode() : 0);
- return hash;
- }
- @Override
- public boolean equals(Object object) {
- // TODO: Warning - this method won't work in the case the id fields are not set
- if (!(object instanceof Category)) {
- return false;
- }
- Category other = (Category) object;
- if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
- return false;
- }
- return true;
- }
- @Override
- public String toString() {
- return cname;
- }
- @Override
- public int compareTo(Object o) {
- return this.id - ((Category) o).id;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement