Java - Entities - Item Catalog

Creating a item catalog class using entities in java.

Imports

package model.entities;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Collection;
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.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

Entities

/* @author Steven Bartsch */
@Entity
@Table(name = "item_catalog")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "ItemCatalog.findAll", query = "SELECT i FROM ItemCatalog i"),
    @NamedQuery(name = "ItemCatalog.findAllDesc", query = "SELECT i FROM ItemCatalog i ORDER BY i DESC"),
    @NamedQuery(name = "ItemCatalog.findByItemid", query = "SELECT i FROM ItemCatalog i WHERE i.itemid = :itemid"),
    @NamedQuery(name = "ItemCatalog.findByItemname", query = "SELECT i FROM ItemCatalog i WHERE i.itemname = :itemname"),
    @NamedQuery(name = "ItemCatalog.findByItemdesc", query = "SELECT i FROM ItemCatalog i WHERE i.itemdesc = :itemdesc"),
    @NamedQuery(name = "ItemCatalog.findByRetailprice", query = "SELECT i FROM ItemCatalog i WHERE i.retailprice = :retailprice"),
    @NamedQuery(name = "ItemCatalog.findByStock", query = "SELECT i FROM ItemCatalog i WHERE i.stock = :stock"),
    @NamedQuery(name = "ItemCatalog.UpdateStock", query = "UPDATE ItemCatalog i SET i.stock = i.stock WHERE i.itemid = :itemid"),
    @NamedQuery(name = "ItemCatalog.AddToStock", query = "UPDATE ItemCatalog i SET i.stock = i.stock+1 WHERE i.itemid = :itemid"),
    @NamedQuery(name = "ItemCatalog.RemoveFromStock", query = "UPDATE ItemCatalog i SET i.stock = i.stock-1 WHERE i.itemid = :itemid"),
    @NamedQuery(name = "ItemCatalog.RemoveItem", query = "DELETE FROM ItemCatalog i WHERE i.itemid = :itemid")
})

Members

public class ItemCatalog implements Serializable{
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "itemid")
    private Integer itemid;
    @Column(name = "itemname")
    private String itemname;
    @Column(name = "itemdesc")
    private String itemdesc;
    @Column(name = "retailprice")
    private BigDecimal retailprice;
    @Column(name = "stock")
    private Integer stock;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "itemCatalog")
    private Collection<UserCart> userCartCollection;
    @JoinColumn(name = "cataid", referencedColumnName = "cataid")
    @ManyToOne
    private ItemCategory cataid;
    @JoinColumn(name = "vendorid", referencedColumnName = "vendorid")
    @ManyToOne
    private Vendor vendorid;

Methods

    public ItemCatalog(){
        itemid = null;
        itemname = "";
        itemdesc = "";
        retailprice = null;
        cataid = null;
        vendorid = null;
    }

    public ItemCatalog(int itemid, String itemname, String itemdesc, BigDecimal retailprice){
        this.itemid = itemid;
        this.itemname = itemname;
        this.itemdesc = itemdesc;
        this.retailprice = retailprice;
    }

    public ItemCatalog(Integer itemid){
        this.itemid = itemid;
    }

    public Integer getItemid(){
        return itemid;
    }

    public void setItemid(Integer itemid){
        this.itemid = itemid;
    }

    public String getItemname(){
        return itemname;
    }

    public void setItemname(String itemname){
        this.itemname = itemname;
    }

    public String getItemdesc(){
        return itemdesc;
    }

    public void setItemdesc(String itemdesc){
        this.itemdesc = itemdesc;
    }

    public BigDecimal getRetailprice(){
        return retailprice;
    }

    public void setRetailprice(BigDecimal retailprice){
        this.retailprice = retailprice;
    }

    public Integer getStock(){
        return stock;
    }

    public void setStock(Integer stock){
        this.stock = stock;
    }

    @XmlTransient
    public Collection<UserCart> getUserCartCollection(){
        return userCartCollection;
    }

    public void setUserCartCollection(Collection<UserCart> userCartCollection){
        this.userCartCollection = userCartCollection;
    }

    public ItemCategory getCataid(){
        return cataid;
    }

    public void setCataid(ItemCategory cataid){
        this.cataid = cataid;
    }

    public Vendor getVendorid(){
        return vendorid;
    }

    public void setVendorid(Vendor vendorid){
        this.vendorid = vendorid;
    }

Overrides

    @Override
    public int hashCode(){
        int hash = 0;
        hash += (itemid != null ? itemid.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 ItemCatalog)){
            return false;
        }
        ItemCatalog other = (ItemCatalog) object;
        if((this.itemid == null && other.itemid != null) || (this.itemid != null && !this.itemid.equals(other.itemid))){
            return false;
        }
        return true;
    }

    @Override
    public String toString(){
        return "model.entities.ItemCatalog[ itemid=" + itemid + " ]";
    }
}