views:

51

answers:

2

Hi,

I am a college student who do not have a lot of experience on Hibernate or Grails. The main question that I have is mainly about where does cascading apply, does it apply only to attributes where there is an database entry for it or other wise?

so for example If I have 2 Domains A and B... where B has hastable that is filled with A's. If I delete A, do I have to manually remove the hashtable entry in B of that particular A entry? If not what behavior should I set to be able to remove it?

P.S. My first post... I apologize if there is not enough detail, but I really do not have much experience to properly describe my question..

A: 

For one to many relationship the default strategy is save and update. For delete you will have to have belongsTo clause.

See section 5.2.1.2 for details in the following document

See http://grails.org/doc/1.0.x/guide/5.%20Object%20Relational%20Mapping%20%28GORM%29.html for details

Paras
A: 

The main question that I have is mainly about where does cascading apply, does it apply only to attributes where there is an database entry for it or other wise?

Cascading allows to "propagate" operation(s) like persist, merge, save-update,... along an association between entities. So, if A has an association with B, it is possible to cascade operations done on A to B.

For example if I have 2 Domains A and B... where B has hashtable that is filled with A's. If I delete A, do I have to manually remove the hashtable entry in B of that particular A entry?

As I said, cascading is done along an association. Here, you described an association from B to A so nothing will get cascaded from A to B. Now, if this association is bi-directional (i.e. if you can navigate from A to B), then you will be able to cascade operations from A to B.

But you need to understand that cascading doesn't affect in memory content by itself, removing an A from a collection has to be done by you.

See also

Pascal Thivent
Hi,Thanks for the reply, I have read through the documentation you have posted. From what I have read, I will try to give an more detailed example...In grails there is hasMany[] and belongTo[].. Domain A has an belongTo[b:B] while Domain B has an hasMany[a:A] and B has cascade:'delete-orphan'. Does this mean:If I delete an A now, the hashtable in B the keeps tracks of A's will be unaffected, but the instant that I delete a B, I will also delete the A's because they are now 'orphaned' right?
T-Lin