/* * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. * * You may not modify, use, reproduce, or distribute this software * except in compliance with the terms of the license at: * http://developer.sun.com/berkeley_license.html */ package entity; import java.io.Serializable; import java.math.BigDecimal; import java.util.Collection; import java.util.Date; import javax.persistence.Basic; import javax.persistence.CascadeType; 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.ManyToOne; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; import javax.persistence.OneToMany; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlTransient; /** * * @author tgiunipero */ @Entity @Table(name = "product") @NamedQueries({ @NamedQuery(name = "Product.findAll", query = "SELECT p FROM Product p"), @NamedQuery(name = "Product.findById", query = "SELECT p FROM Product p WHERE p.id = :id"), @NamedQuery(name = "Product.findByName", query = "SELECT p FROM Product p WHERE p.name = :name"), @NamedQuery(name = "Product.findByPrice", query = "SELECT p FROM Product p WHERE p.price = :price"), @NamedQuery(name = "Product.findByLastUpdate", query = "SELECT p FROM Product p WHERE p.lastUpdate = :lastUpdate")}) //@XmlRootElement //@XmlAccessorType(XmlAccessType.FIELD) public class Product implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Basic(optional = false) @Column(name = "id") private Integer id; @Basic(optional = false) @Column(name = "name") private String name; @Basic(optional = false) @Column(name = "price", precision = 15, scale = 2) private BigDecimal price; @Basic(optional = false) @Column(name = "last_update") @Temporal(TemporalType.TIMESTAMP) private Date lastUpdate; @JoinColumn(name = "category_id", referencedColumnName = "id") @ManyToOne(optional = false) private Category category; // @XmlTransient // //@JsonIgnore @OneToMany(cascade = CascadeType.ALL, mappedBy = "product") private Collection<OrderedProduct> orderedProductCollection; public Product() { } public Product(Integer id) { this.id = id; } public Product(Integer id, String name, BigDecimal price, Date lastUpdate) { this.id = id; this.name = name; this.price = price; this.lastUpdate = lastUpdate; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public BigDecimal getPrice() { return price; } public void setPrice(BigDecimal price) { this.price = price; } public Date getLastUpdate() { return lastUpdate; } public void setLastUpdate(Date lastUpdate) { this.lastUpdate = lastUpdate; } public Category getCategory() { return category; } public void setCategory(Category category) { this.category = category; } public Collection<OrderedProduct> getOrderedProductCollection() { return orderedProductCollection; } public void setOrderedProductCollection(Collection<OrderedProduct> orderedProductCollection) { this.orderedProductCollection = orderedProductCollection; } @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 Product)) { return false; } Product other = (Product) 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 "entity.Product[id=" + id + "]"; } }