HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 

"EJB 3.0 Preview"
Vol. 9, Issue 11, p. 22

	



Listing 1

@Entity
@Table(name="ORDER_TABLE")
public class Order implement java.io.Serializable
{
   private int orderId;
   private Date orderDate;
   private Collection<OrderItem> orderItems;


   @Id @Column(name="ORDER_ID")
   public int getOrderId() { return orderId; }

   public void setOrderId(int id) { orderId = id; }

   @OneToOne @JoinColumn("CUST_ID")
   public Customer getCustomer() { return customer; }

   public void setCustomer(Customer cust) { this.customer = cust; }

   @OneToMany(cascade={CascadeType.ALL}) @JoinColumn("ITEM_ORDER_ID")
   public Collection<OrderItem> getOrderItems() { return orderItems; }

   public void setOrderItems(Collection<OrderItem> items) { this.orderItems = items; }

}

Listing 2

@Stateful
public class ShoppingCartBean implements ShoppingCart
{
   @Inject EntityManager entityManager;

...

   public Order checkout()
   {
      Order order = new Order();
      order.setCustomer(this.customer);
      order.setOrderDate(new Date());
      order.setOrderItems(this.itemsInCart);
      order.setOrderStatus("INITIAL");

      entityManager.create(order);
      return Order;
   }
}

Listing 3

@Stateless
public class SessionBean implements Session
{
   @Inject EntityManager manager;

   public Customer getCustomerByName(String name)
   {
      Query query = manager.createQuery("from Customer c where c.name = :name");
      query.setArgument("name", name);
      return query.getUniqueResult();
   }

   public void updateCustomerInfo(Customer cust)
   {
      manager.merge(cust);
   }
}
  
 

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.