Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

orm

hibernate

jpa

Whenever i do OR mapping, i make all relationships bidirectional. That is, i totally avoid unidirectional relationships. Here are the reasons:

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?

like image 859
nash Avatar asked Dec 10 '25 08:12

nash


1 Answers

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.

like image 57
hvgotcodes Avatar answered Dec 13 '25 07:12

hvgotcodes