Jboss Ejb3.0 Entity Bean

作者:简简单单 2008-01-12

Order.java
package org.jboss.tutorial.entity.bean;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratorType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Id;
import javax.persistence.CascadeType;
import javax.persistence.FetchType;
import java.util.ArrayList;
import java.util.Collection;
@Entity
@Table(name = "PURCHASE_ORDER")
//If the table name isn't specified it defaults to the bean name
//of the class. For instance, the LineItem EJB would be mapped to
//the LINEITEM table
public class Order implements java.io.Serializable
{
   private int id;
   private double total;
   private Collection lineItems;
   @Id(generate = GeneratorType.AUTO)
   public int getId()
   {
      return id;
   }
   public void setId(int id)
   {
      this.id = id;
   }
   public double getTotal()
   {
      return total;
   }
   public void setTotal(double total)
   {
      this.total = total;
   }
   public void addPurchase(String product, int quantity, double price)
   {
      if (lineItems == null) lineItems = new ArrayList();
      LineItem item = new LineItem();
      item.setOrder(this);
      item.setProduct(product);
      item.setQuantity(quantity);

相关文章

精彩推荐