I am a little confused about the rule while making hashcodes for my JPA2 entities.
I have an embedded entity comprising audit columns (lastModifiedDate, createdDate) etc. Should this object pe part of the hashcode for my entity ?
@Entity(name = "CaseStatusEnum")
public class CaseStatus implements java.io.Serializable {
private static final long serialVersionUID = -5936623582710348810L;
@Id
@Column(unique=true,nullable=false,length=30)
private String caseStatus;
@Column(nullable=false,length=100)
private String caseStatusDesc;
@Embedded
private AuditTrail auditTrail;
I suggest you this link to overview concepts around the equals and hashcode function, specially its use within the diferents implementations of Hash and Collections.
overriding equals and hashcode
Then you maybe need to adjust the implementation of equals and hashcode functions depending on the JPA2 implementation you are using. Whatever be, I recommend you to take a look at this article about Hibernate – equals and hashcode to a better understanding of how could your app could be affected overriding this functions.
Regards