Java - Entities - Orders

Creating a orders class using entities in java.

Imports

package model.entities;

import java.io.Serializable;
import java.util.Date;
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.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;

Entities

/* @author Steven Bartsch */
@Entity
@Table(name = "orders")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Orders.findAll", query = "SELECT o FROM Orders o"),
    @NamedQuery(name = "Orders.findByOrderid", query = "SELECT o FROM Orders o WHERE o.orderid = :orderid"),
    @NamedQuery(name = "Orders.findByUserid", query = "SELECT o FROM Orders o WHERE o.userid = :userid ORDER BY o.orderid DESC"),
    @NamedQuery(name = "Orders.findByItems", query = "SELECT o FROM Orders o WHERE o.items = :items"),
    @NamedQuery(name = "Orders.findByQuantities", query = "SELECT o FROM Orders o WHERE o.quantities = :quantities"),
    @NamedQuery(name = "Orders.findByOrderdate", query = "SELECT o FROM Orders o WHERE o.orderdate = :orderdate")})

Members

public class Orders implements Serializable{
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "orderid")
    private Integer orderid;
    @Column(name = "userid")
    private Integer userid;
    @Column(name = "items")
    private String items;
    @Column(name = "quantities")
    private String quantities;
    @Column(name = "orderdate")
    @Temporal(TemporalType.TIMESTAMP)
    private Date orderdate;

Methods

    public Orders(){
        userid = null;
        items = "";
        quantities = "";
        orderdate = null;
    }

    public Orders(int userid, String items, String quantities, Date orderdate){
        this.userid = userid;
        this.items = items;
        this.quantities = quantities;
        this.orderdate = orderdate;
    }

    public Orders(Integer orderid){
        this.orderid = orderid;
    }

    public Integer getOrderid(){
        return orderid;
    }

    public void setOrderid(Integer orderid){
        this.orderid = orderid;
    }

    public Integer getUserid(){
        return userid;
    }

    public void setUserid(Integer userid){
        this.userid = userid;
    }

    public String getItems(){
        return items;
    }

    public void setItems(String items){
        this.items = items;
    }

    public String getQuantities(){
        return quantities;
    }

    public void setQuantities(String quantities){
        this.quantities = quantities;
    }

    public Date getOrderdate(){
        return orderdate;
    }

    public void setOrderdate(Date orderdate){
        this.orderdate = orderdate;
    }

Overrides

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

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