Traversing List through Index is definitely faster than the Iterator over Set, and the implementation of List to achieve many to many relationship notion in Hibernate is also achievable, however the List implementation does skew the association table semantics since you have to define index column in association table through index column directive in List segment which is bound to association table. From a Database perspective this index column does not make sense (Association table in DB for many to many relationship assumes you have two columns which are primary keys to the referencing tables and that's it). If a DBA takes a look at the association table created by Hibernate through List implementation, he will in a state of shock and awe.
So The question is ...
Does it make sense to skew the association table notation in DB for sme performance gain by using List in place of Set and if yes why didn't Gavin King discussed on this topic till now.
All the reference docs in Hibernate 3 advocates to use Set for many to many relationship.
I have implemented the List for many to many relationship in some projects, but it does not make me feel better, may be because I am an ardent DB developer also...Can someone mitigate my intellectual pain by commenting on the above...
<list name="benchmarks" table="Institutions_Benchmarks" inverse="true">
<meta attribute="field-description">benchmarks for this institution</meta>
<key column="INSTITUTION_ID"/>
<index column="col_idx"/>
<many-to-many class="Benchmark" column="BENCHMARK_ID"/>
</list>
vs
<set name="systemtypes" table="Institutions_SystemTypes" inverse="true">
<meta attribute="field-description">system types for this institution</meta>
<key column="INSTITUTION_ID"/>
<many-to-many
class="SystemType"
column="SYSTEMTYPE_ID"/>
</set>
|