Java equal and hashCode with non primitive types
<p><br>
  I have a class with some non primitive members.</p>

<pre><code>class Relation {
 String name;
 Role roleFrom;
 Role roleTo;
}

class Role {
  RoleType roleType;
  String details;
}
class RoleType {
  String typeName;
  String details;
}
</code></pre>

<p>Two relations are equal, when </p>

<ol>
<li>the name are equal</li>
<li>the role type (identified by unique typeName) are equal for the Role members (roleFrom and roleTo)</li>
</ol>

<p>How to write <code>equals</code> and <code>hashCode</code> for class <code>Relation</code>. When tried with Netbeans, it only displays 3 fields (<code>name</code>, <code>roleFrom</code> and <code>roleTo</code>). Is it because, one should not access the primitive types in roleFrom  and roleTo (roleType -> typeName). Or, please show an implementation.</p>

<p>thanks.</p>
