Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package Entities; import java.io.Serializable; import java.util.HashMap; 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.Lob; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; import javax.persistence.Table; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import org.apache.commons.lang3.SerializationUtils; /** * * @author bhanu */ @Entity @Table(name = "Orders") @NamedQueries({ @NamedQuery(name = "Orders.findAll", query = "SELECT o FROM Orders o") }) public class Orders 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) @NotNull @Size(min = 1, max = 10) @Column(name = "Username") private String username; @Basic(optional = false) @NotNull @Lob @Column(name = "OrderMap") private byte[] orderMap; @Basic(optional = false) @NotNull @Column(name = "Cost") private double cost; public Orders() { } public Orders(Integer id) { this.id = id; } public Orders(String username, byte[] orderMap, double cost) { this.username = username; this.orderMap = orderMap; this.cost = cost; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public byte[] getOrderMap() { return orderMap; } public void setOrderMap(byte[] orderMap) { this.orderMap = orderMap; } public double getCost() { return cost; } public void setCost(double cost) { this.cost = cost; } @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 Orders)) { return false; } Orders other = (Orders) 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 "Entities.Orders[ id=" + id + " ]"; } public HashMap<Products, Integer> getOrderContents() { HashMap<Products, Integer> contents = (HashMap) SerializationUtils.deserialize(orderMap); return contents; } }