1. You need to do whatever your business rules require. If it only takes 1 field to differentiate, or all of them. If there is no way to tell that a user isn't the same w/o checking out his address in another table, then put address in your .equals. Just be warned of the implications when it comes to lazy loading and session management when you implement this. There isn't a set formula, just normal guidelines.
A good way to define your equals and hashcode methods is to use attributes that won't normally change in the object's lifetime of being in memory. If these attributes DO change, which is fine, delete it, make a new one, and update references to point to the new one; or make sure you change them in a safe context, where the object is protected somehow so another part of your program isn't using it.
2. I would say it is reasonable to call super in B's hashcode if it doesn't have any of its own identifying features. However, I have to question why you have B extending A if B doesn't have its own identifying features. If the only way to differentiate two classes that extend the same class exist in A, you have to use A's equals/hashcode methods or write some custom ones.
_________________ Chris
If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.
|