开发者

ejb 3 :is it OK to make all relationships birectional?

Whenever i do OR mapping, i make all relationships bidirectional. That is, i totally avoid unidirectional relationships. Here are the r开发者_如何学运维easons:

1)To have consistency in all the relationships. So for example while persisting, i don't have to think whether the relationship is unidirectional or bidirectional. Just hook them up from both sides in all cases.

2)For future safety, if a situation comes when references are required from both sides. If i had used unidirectional, i would have to make changes to make it bidirectional.

does anybody prefer this approach of making all relationships bidirectional? Has anybody run into serious performance issues following this approach?


It is something you can do, however, I think it is possibly a poor design choice to just do it with no actual business reason. In other words, if your code needs bidirectional relationships in its domain classes, have at it, if it does not need it then IMHO dont do it.

Note that you can run into performance issues with creating relationships you do not need if you do not lazy load.


That depends on which operation happens more often - if you rather search for objects, count them and /or show some of them, the bidirectional references are useful. But if the adding/removing of an object is the frequent operation, use rather one-directional ones.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜