• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

CMR & cascade-delete question

 
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic