Say I have a join table that joins table1 and table2. This join table is going to define equals and compareTo based on table1 and table2, so I would probably be tempted to write this:
Code:
compareTo (JoinTable rhs) {
return new CompareToBuilder()
.append(getTable1, rhs.getTable1())
.append(getTable2, rhs.getTable2())
.toComparison()
}
Say I query for a list of these objects, then throw them all in a TreeSet. Will I then get two selects for every object because TreeSet is called getTable1() and getTable2() all over the place? If so, is there a way to define equality on the IDs, rather then the full objects?