ejbCreate method of a containing entity bean (LineItem).

Architect's Corner
Entity bean relationships in EJB 1.1
Part 1: The basic technique

Grant Holland
Listing 2. ejbCreate method of a containing entity bean (LineItem).


    public LineItemPK ejbCreate(
			int         	lineItemID,
			int         	orderID,
			int         	quantity,
			Product     	product 	)
		throws CreateException,RemoteException
    {

    LineItemPK pk;

    try
    {
	// capture all 3 field types
	this.lineItemID = lineItemID; // persistent data
	this.orderID = orderID;       // persistent data
	this.quantity = quantity;     // persistent data
	this.product = product;       // related EJB object
	this.productName =            // related key
		((ProductPK)product.getPrimaryKey()).productName;

	/*
	// persist persistent data
	< write “lineItemID”       to persistent store >
	< write “orderID”          to persistent store >
	< write “quantity”         to persistent store >

	// persist related key
	< write “productName”   to persistent store >
	*/

	// create and initialize Primary Key object
	LineItemPK pk = new LineItemPK();    // make PK
	pk.lineItemID = lineItemID;          // capture identity field
	pk. orderID = orderID;               // capture identity field
    }
    catch(Exception e)
    {
	throw new CreateException(e.getMessage());
    }
    
    return pk;
  }