Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CMR & cascade-delete question

 
Jim Janssens
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, if I understand the principle of the cascade-delete well then you should put the tag in the part of the relation which you want to be deleted automatically if you delete an instance of the other part. Assume the 'order-orderline' relation. One order can have many orderlines. When I remove the order I want the referencing orderlines to be removed.

So, I define something like this:

ejb-relationship-role : order
multiplicty: one
cmr-field: orderLines


ejb-relationship-role : orderLine
multiplicty: many
cmr-field: order
cascade-delete

If I delete the order, the referenced orderLines are deleted also, right ?

--------

Second, the spec also dictates that the other relation (which does not have the cascade-delete) should have a multiplicity of one. Why is this exactly ?

Assume that I switch the cascade-delete of the above example :

ejb-relationship-role : order
multiplicty: one
cmr-field: orderLines
cascade-delete

ejb-relationship-role : orderLine
multiplicty: many
cmr-field: order


When I remove an orderLine, the corresponding Order will also be removed. But according to the spec this should not be possible then ? Why ? The only problem I see is that there will be some orderLines left which point to a non existing order...

Thank you.
 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ejb-relationship-role : Many order lines map to one order
multiplicty: many
cmr-field: orderLines
cascade-delete


ejb-relationship-role : One order has many order lines
multiplicty: one
cmr-field: order

Order Line is holding a reference to an Order so it needs to know the course of action when an order is deleted not the other way around. There might be some beans that have a CMR with Order but also make sense independently (ie w/o a corresponding order instance). They s'dnt get deleted. So the detail table needs to be aware of the master.

If multiple Order Lines could map to multiple orders, then just because one of the orders got deleted , you would't want to delete the linked order lines as other orders might be referencing them.
 
Jim Janssens
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, it sounds logical that you dont want to delete the other orderlines. But is it possible ? In other words; can the opposite ejb-relation of who has a cascade-delete tag by multiple ? Or is this disallowed.

The spec is not very clear about this.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic