Order Item一般由product,order组成。 下面就是Order Item
1 OrderDetailId
import javax.persistence.Column;
import javax.persistence.Embeddable;
@Embeddable
public class OrderDetailId implements java.io.Serializable {
// Fields
private Integer purchaseordernumber;
private String productcode;
// Constructors
/** default constructor */
public OrderDetailId() {
}
/** full constructor */
public OrderDetailId(Integer purchaseordernumber, String productcode) {
this.purchaseordernumber = purchaseordernumber;
this.productcode = productcode;
}
// Property accessors
@Column(name="PURCHASEORDERNUMBER", nullable=false)
public Integer getPurchaseordernumber() {
return this.purchaseordernumber;
}
public void setPurchaseordernumber(Integer purchaseordernumber) {
this.purchaseordernumber = purchaseordernumber;
}
@Column(name="PRODUCTCODE", nullable=false, length=15)
public String getProductcode() {
return this.productcode;
}
public void setProductcode(String productcode) {
this.productcode = productcode;
}
public boolean equals(Object other) {
if ( (this == other ) ) return true;
if ( (other == null ) ) return false;
if ( !(other instanceof OrderDetailId) ) return false;
OrderDetailId castOther = ( OrderDetailId ) other;
return ( (this.getPurchaseordernumber()==castOther.getPurchaseordernumber()) || ( this.getPurchaseordernumber()!=null && castOther.getPurchaseordernumber()!=null && this.getPurchaseordernumber().equals(castOther.getPurchaseordernumber()) ) )
&& ( (this.getProductcode()==castOther.getProductcode()) || ( this.getProductcode()!=null && castOther.getProductcode()!=null && this.getProductcode().equals(castOther.getProductcode()) ) );
}
public int hashCode() {
int result = 17;
result = 37 * result + ( getPurchaseordernumber() == null ? 0 : this.getPurchaseordernumber().hashCode() );
result = 37 * result + ( getProductcode() == null ? 0 : this.getProductcode().hashCode() );
return result;
}
}
2. OrderDetail
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Table;
import javax.persistence.IdClass;
import javax.persistence.ManyToOne;
/**
* OrderDetail entity. @author MyEclipse Persistence Tools
*/
@Entity
@Table(name="ORDERDETAIL"
,schema="dbo"
,catalog="ssh"
)
//@IdClass(OrderDetailId.class)
public class OrderDetail implements java.io.Serializable {
// Fields
private OrderDetailId id;
private Integer quantityordered;
private double priceeach;
private short orderlinenumber;
private Order order;
private Product product;
// Constructors
/** default constructor */
public OrderDetail() {
}
/** minimal constructor */
public OrderDetail(OrderDetailId id) {
this.id = id;
}
/** full constructor */
public OrderDetail(OrderDetailId id, Integer quantityordered, double priceeach, short orderlinenumber) {
this.id = id;
this.quantityordered = quantityordered;
this.priceeach = priceeach;
this.orderlinenumber = orderlinenumber;
}
// Property accessors
@EmbeddedId
@AttributeOverrides( {
@AttributeOverride(name="purchaseordernumber", column=@Column(name="PURCHASEORDERNUMBER", nullable=false) ),
@AttributeOverride(name="productcode", column=@Column(name="PRODUCTCODE", nullable=false, length=15) ) } )
public OrderDetailId getId() {
return this.id;
}
public void setId(OrderDetailId id) {
this.id = id;
}
@Column(name="QUANTITYORDERED")
public Integer getQuantityordered() {
return this.quantityordered;
}
public void setQuantityordered(Integer quantityordered) {
this.quantityordered = quantityordered;
}
@Column(name="PRICEEACH", precision=10)
public double getPriceeach() {
return this.priceeach;
}
public void setPriceeach(double priceeach) {
this.priceeach = priceeach;
}
@Column(name="ORDERLINENUMBER")
public short getOrderlinenumber() {
return this.orderlinenumber;
}
public void setOrderlinenumber(short orderlinenumber) {
this.orderlinenumber = orderlinenumber;
}
@ManyToOne(targetEntity=Order.class)
@JoinColumn(name="PURCHASEORDERNUMBER" , insertable=false, updatable=false)
public Order getOrder() {
return order;
}
public void setOrder(Order order) {
this.order = order;
}
@ManyToOne(targetEntity=Product.class)
@JoinColumn(name="PRODUCTCODE" , insertable=false, updatable=false)
public Product getProduct() {
return product;
}
public void setProduct(Product product) {
this.product = product;
}
}
3. 在Order怎么用
@OneToMany(mappedBy="order",fetch = FetchType.EAGER)
@JoinColumn(name="purchaseordernumber")
public List<OrderDetail> getOrderDetails() {
return orderDetails;
}
public void setOrderDetails(List<OrderDetail> orderDetails) {
this.orderDetails = orderDetails;
}
Jsp显示
<table id="list" cellspacing="0">
<tr>
<td><s:text name="order.orderCode"/></td>
<td>order date</td>
<td> requireddate</td>
<td> shippeddate</td>
</tr>
<s:iterator value="orders">
<tr>
<td><input type="checkbox" name="order.purchaseordernumber" value="${purchaseordernumber}">${purchaseordernumber}</td>
<td><s:text name="global.format.date"><s:param value="orderdate"></s:param></s:text></td>
<td><s:text name="global.format.date"><s:param value="requireddate"></s:param></s:text></td>
<td><s:text name="global.format.date"><s:param value="shippeddate"></s:param></s:text></td>
<td><a href="${pageContext.request.contextPath}/order_delete.action?order.purchaseordernumber=${purchaseordernumber}">Delete Order</a></td>
</tr>
</s:iterator>
</table>