One potential solution, assuming you
- you must redefine equals for your implementations
- You want to be lazy
- You do not mind treating hashcode () and equals () methods as black boxes
- Do not pay attention to using an additional tool at compile time.
- try to use the Lombok useful EqualsAndHashcode Designation to handle this for you. Of course, probably, you probably should probably read the links that @StudiousJoseph mentioned in your answer, so you understand how to write the right equals / hashcode methods, but it is a tool that can help reduce some of the problems and mistakes when writing these methods yourself.
As mentioned above, in your case you need to at least use this annotation or override equals () / hashcode () in your relationship class and possibly also your own Role and Roletype class if you need to configure peer behavior on them.
Edit: I just noticed that you are using Netbeans. This may be relevant if you want to try Lombok: http://wiki.netbeans.org/Lombok#IDE_support
source share