Java - Entities - Item Category

Creating a item category class using entities in java.

Imports

package model.entities;

import java.io.Serializable;
import java.util.Collection;
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.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_category")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "ItemCategory.findAll", query = "SELECT i FROM ItemCategory i"),
    @NamedQuery(name = "ItemCategory.findByCataid", query = "SELECT i FROM ItemCategory i WHERE i.cataid = :cataid"),
    @NamedQuery(name = "ItemCategory.findByCataname", query = "SELECT i FROM ItemCategory i WHERE i.cataname = :cataname")})

Members

public class ItemCategory implements Serializable{
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "cataid")
    private Integer cataid;
    @Column(name = "cataname")
    private String cataname;
    @OneToMany(mappedBy = "cataid")
    private Collection<ItemCatalog> itemCatalogCollection;

Methods

    public ItemCategory(){
    }

    public ItemCategory(Integer cataid){
        this.cataid = cataid;
    }

    public Integer getCataid(){
        return cataid;
    }

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

    public String getCataname(){
        return cataname;
    }

    public void setCataname(String cataname){
        this.cataname = cataname;
    }

    @XmlTransient
    public Collection<ItemCatalog> getItemCatalogCollection(){
        return itemCatalogCollection;
    }

    public void setItemCatalogCollection(Collection<ItemCatalog> itemCatalogCollection){
        this.itemCatalogCollection = itemCatalogCollection;
    }

Overrides

    @Override
    public int hashCode(){
        int hash = 0;
        hash += (cataid != null ? cataid.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object){
        if(!(object instanceof ItemCategory)){
            return false;
        }
        ItemCategory other = (ItemCategory) object;
        if((this.cataid == null && other.cataid != null) || (this.cataid != null && !this.cataid.equals(other.cataid))){
            return false;
        }
        return true;
    }

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