I'm a Hibernate newbie, so I apologize in advance if my questions sound stupid :-). I really want to get a good handle on the best approach with respect to database performance, i.e., never retrieve more records that I need, and always try to make the fewest database calls.
As we all know, in the relational model, a many-to-many or ternary relationship is represented as a link table. My question is: should this link table be modeled as a top level entity in my domain model? My typical use cases are:
1. in a many-to-many association, with tables A, B, and L, I always want to find the list of B given an A
2. in a ternary association, with tables A, B, C, and L, I always want to find the list of C given an A and a B
For my use case, it seems that modeling the link table as a top level entity always seem to make sense, as it gives me exact control how many records/object instances I retrieve from the database.
Now another follow up question:
In my LClass that maps to the link table, should I have many-to-one references to AClass, BClass, and CClass, or should I just have regular attributes for a_id, b_id, and c_id, if all I want to do is to update the associations in the link table?
|