File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes CMR Questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "CMR Questions" Watch "CMR Questions" New topic

CMR Questions

Edmund Yong
Ranch Hand

Joined: Nov 16, 2003
Posts: 164
I have two entity beans with a 1:Many CMR relationship. "Order" has many "OrderItem". An "Order" has an order number as its primary key. An "OrderItem" has an item number as its primary key, and it also has an order number that indicates the exact Order it belongs to. An "OrderItem" cannot exist without an "Order". That is, if I delete the "Order", all the related "OrderItem" will also be deleted implicitly.
I don't have problem coding the OrderItemBean, but I have with the OrderBean.
public abstract class OrderBean implements EntityBean {
public abstract String getOrderNumber();
public abstract void setOrderNumber(String orderNumber);
// CMR fields
public abstract void setOrderItems(Collection orderItemsLocal);
public abstract Collection getOrderItems();
(1) If I call Order.remove(), will the related Order Items get deleted from the database?
(2) Within OrderBean, if I call setOrderItems() with an Empty Collection, does it delete the related Order Items from the database, or does it merely remove the relationship only?
Thanks in advance.

SCJP 1.2, SCWCD 1.4
Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
Search your appserver documentation for "cascade delete" or something like that. It should be possible.

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Edmund Yong
Ranch Hand

Joined: Nov 16, 2003
Posts: 164
I'm using the J2EE implementation along with Cloudscape database.
Sergiu Truta
Ranch Hand

Joined: Dec 16, 2003
Posts: 121
From ejb-jar_2_0.dtd
<!ELEMENT cascade-delete EMPTY>
The cmp-field element describes a container-managed field. The
field element includes an optional description of the field, and the
name of the field.
Used in: entity
so inside a relationship, on the side of the relationship where the multiplicity is "Many" you have to specify <cascade-detele/>:
<cascade-delete/> I'm walking the path...
I agree. Here's the link:
subject: CMR Questions
It's not a secret anymore!