alspaughb wrote:
1. What is the recommended way to compute hashcodes when there is more than one property in the business key? Is it recommended to use an implementation like that on page 124? If so, how were the numbers "14" and "29" chosen?
If you use HibernateTools reverse engineering you will get something like:
Code:
public int hashCode() {
int result = 17;
result = 37 * result + getBezBankenverfahren();
result = 37 * result + getNrMandant();
result = 37 * result + ( getDatenstichtag() == null ? 0 : this.getDatenstichtag().hashCode() );
result = 37 * result + (int) getNrGeschaeft();
result = 37 * result + getUnterNrGeschaeft();
return result;
}
Here you have 17 and 37. The number are more or less arbitrary.
You just need to add some chaos, so that the hashkeys are unique
in most cases.
alspaughb wrote:
2. I can see where two objects with the same business keys will always return the same hashcodes. Conversely, how concerned should I be about the possibility that two objects with different business keys could map to the same hashcode on rare occasions?
A HashMap works in two phases:
1. First select a table with the hashkey,
2. go through that table using the equals method.
This last step guarantees that you will never have collisions.
A bad designed hashCode method only results in a bad performance.
Look up the implementation of HashMap.
alspaughb wrote:
3. I understand that business keys should change "rarely" and that they should not be changed while the domain object is in a set. Is it acceptable (for example to handle cases where the user wants to correct a typo in a person's name) to first remove the object from the set, make the change, and then add it back to the set? Are there other situations that I need to watch for when a component property of a business key changes?
I am not sure about this. Just try it.
Hope I could help