Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CMR Questions

 
Edmund Yong
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
...
}
Questions:
(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.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Search your appserver documentation for "cascade delete" or something like that. It should be possible.
 
Edmund Yong
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using the J2EE implementation along with Cloudscape database.
 
Sergiu Truta
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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/>:
<multiplicity>Many</multiplicity>
<cascade-delete/>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic