I have a domain Class named Subscriber
and its definition is something like this:
public class Subscriber {
private long id;
private String email;
private String subscriberName;
private Topic subscribingTopic;
//other attributes and getters setters.
}
public class Topic{
private long id;
private String topicName; //unique
}
My problem is I need to override the equal() and hashCode() methods of this Subscriber class. Overriding equal() is somewhat easy task (just comparing basic attributes, in this case there are three of them). But I am facing problems while overriding hashCode() method. How I can write hashCode() that I can trust to be used by hibernate safely, while managing my domains. Can I trust IDE generated one?
Any help will be appreciated and thanks in advance!