开发者

Hibernate or Grails - Need help understanding cascade

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? I开发者_开发知识库f 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..


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

  • 10.11. Transitive persistence in the Hibernate Reference Documentation


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜