Order and LineItem in cmp, how?

I've read Sun's jsdk1.2.1 examples (ejb 1.1) about

mapping 1-n "weak"-relationship, such asOrder and

LineItems. In the example,LineItems was implemented

as ordinary serializable class, whileOrder was

implemented as bmp-entity bean.

I would like to know how to "convert" that "schema"

to cmp, especially how to instruct (in deployment

descriptor) the container to update tableline_items

in dbms via theOrder entity bean.

Is it as simple as I'm asumming, just need to add some

line in the dd (part or<entity>), or is it related with

transaction (i.e I need to use transaction to update/

insert into tableorder andline_items)?

publicclass LineItems()

{

privateint lineNumber;

private String orderId;

/* other fields */

publicint getLineNumber() ...

publicvoid setLineNumber() ...

/* and soon */

}

publicclass OrderBeanimplements EntityBean{

public String orderId;

private ArrayList lineItems;

public String ejbCreate(String orderId,ArrayList lineItems)

{

this.orderId = orderId;

/* Is this correct?

this.lineItems = lineItems;

*/

returnnull;

}

}

Thanks in advance.

[2213 byte] By [verdi96] at [2007-9-26 3:37:39]
# 1

First you need to make both LineItem and Order CMP entities. Then you need to write Java code to manage the 1-n relationship. With EJB2.0, you can simply use container managed relationship without writing Java code for relationship. The following code sample is for EJB1.1:

public class LineItemBean implements EntityBean {

...

}

public class OrderBean implements EntityBean {

public String orderId;

private Collection lineItems;

public String ejbCreate(String orderId) {

this.orderId = orderId;

this.lineItems = new ArrayList(); //no lineItem yet

return null;

}

public void addLineItem(...) {

//get LineItemHome object

lineItems.add(lineItemHome.create(...));

}

public void ejbLoad() {

// get lineItemHome

lineItems = lineItemHome.findByOrderId(orderId);

}

}

yilin at 2007-6-29 12:10:18 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...