/*
* 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 javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
/**
*
* @author tgiunipero
*/
@Entity
@Table(name = "ordered_product")
@NamedQueries({
@NamedQuery(name = "OrderedProduct.findAll", query = "SELECT o FROM OrderedProduct o"),
@NamedQuery(name = "OrderedProduct.findByCustomerOrderId", query = "SELECT o FROM OrderedProduct o WHERE o.orderedProductPK.customerOrderId = :customerOrderId"),
@NamedQuery(name = "OrderedProduct.findByProductId", query = "SELECT o FROM OrderedProduct o WHERE o.orderedProductPK.productId = :productId"),
@NamedQuery(name = "OrderedProduct.findByQuantity", query = "SELECT o FROM OrderedProduct o WHERE o.quantity = :quantity")})
//@XmlRootElement
//@XmlAccessorType(XmlAccessType.FIELD)
public class OrderedProduct implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
protected OrderedProductPK orderedProductPK;
@Basic(optional = false)
@Column(name = "quantity")
private short quantity;
// @XmlTransient
// //@JsonIgnore
@JoinColumn(name = "product_id", referencedColumnName = "id", insertable = false, updatable = false)
@ManyToOne(optional = false)
private Product product;
// @XmlTransient
// //@JsonIgnore
@JoinColumn(name = "customer_order_id", referencedColumnName = "id", insertable = false, updatable = false)
@ManyToOne(optional = false)
private CustomerOrder customerOrder;
public OrderedProduct() {
}
public OrderedProduct(OrderedProductPK orderedProductPK) {
this.orderedProductPK = orderedProductPK;
}
public OrderedProduct(OrderedProductPK orderedProductPK, short quantity) {
this.orderedProductPK = orderedProductPK;
this.quantity = quantity;
}
public OrderedProduct(int customerOrderId, int productId) {
this.orderedProductPK = new OrderedProductPK(customerOrderId, productId);
}
public OrderedProductPK getOrderedProductPK() {
return orderedProductPK;
}
public void setOrderedProductPK(OrderedProductPK orderedProductPK) {
this.orderedProductPK = orderedProductPK;
}
public short getQuantity() {
return quantity;
}
public void setQuantity(short quantity) {
this.quantity = quantity;
}
public Product getProduct() {
return product;
}
public void setProduct(Product product) {
this.product = product;
}
public CustomerOrder getCustomerOrder() {
return customerOrder;
}
public void setCustomerOrder(CustomerOrder customerOrder) {
this.customerOrder = customerOrder;
}
@Override
public int hashCode() {
int hash = 0;
hash += (orderedProductPK != null ? orderedProductPK.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 OrderedProduct)) {
return false;
}
OrderedProduct other = (OrderedProduct) object;
if ((this.orderedProductPK == null && other.orderedProductPK != null) || (this.orderedProductPK != null && !this.orderedProductPK.equals(other.orderedProductPK))) {
return false;
}
return true;
}
@Override
public String toString() {
return "entity.OrderedProduct[orderedProductPK=" + orderedProductPK + "]";
}
}