/*
* 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;
/**
*
* @author tgiunipero
*/
@Entity
@Table(name = "customer_order")
@NamedQueries({
@NamedQuery(name = "CustomerOrder.findAll", query = "SELECT c FROM CustomerOrder c"),
@NamedQuery(name = "CustomerOrder.findById", query = "SELECT c FROM CustomerOrder c WHERE c.id = :id"),
@NamedQuery(name = "CustomerOrder.findByCustomer", query = "SELECT c FROM CustomerOrder c WHERE c.customer = :customer"), // manually created
@NamedQuery(name = "CustomerOrder.findByAmount", query = "SELECT c FROM CustomerOrder c WHERE c.amount = :amount"),
@NamedQuery(name = "CustomerOrder.findByDateCreated", query = "SELECT c FROM CustomerOrder c WHERE c.dateCreated = :dateCreated"),
@NamedQuery(name = "CustomerOrder.findByConfirmationNumber", query = "SELECT c FROM CustomerOrder c WHERE c.confirmationNumber = :confirmationNumber")})
public class CustomerOrder 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 = "amount")
private BigDecimal amount;
@Basic(optional = false)
@Column(name = "date_created")
@Temporal(TemporalType.TIMESTAMP)
private Date dateCreated;
@Basic(optional = false)
@Column(name = "confirmation_number")
private int confirmationNumber;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "customerOrder")
private Collection<OrderedProduct> orderedProductCollection;
@JoinColumn(name = "customer_id", referencedColumnName = "id")
@ManyToOne(optional = false)
private Customer customer;
public CustomerOrder() {
}
public CustomerOrder(Integer id) {
this.id = id;
}
public CustomerOrder(Integer id, BigDecimal amount, Date dateCreated, int confirmationNumber) {
this.id = id;
this.amount = amount;
this.dateCreated = dateCreated;
this.confirmationNumber = confirmationNumber;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public BigDecimal getAmount() {
return amount;
}
public void setAmount(BigDecimal amount) {
this.amount = amount;
}
public Date getDateCreated() {
return dateCreated;
}
public void setDateCreated(Date dateCreated) {
this.dateCreated = dateCreated;
}
public int getConfirmationNumber() {
return confirmationNumber;
}
public void setConfirmationNumber(int confirmationNumber) {
this.confirmationNumber = confirmationNumber;
}
public Collection<OrderedProduct> getOrderedProductCollection() {
return orderedProductCollection;
}
public void setOrderedProductCollection(Collection<OrderedProduct> orderedProductCollection) {
this.orderedProductCollection = orderedProductCollection;
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
@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 CustomerOrder)) {
return false;
}
CustomerOrder other = (CustomerOrder) 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.CustomerOrder[id=" + id + "]";
}
}