public class CategoryPK implements Serializable {
String name;
Date createDate;
Listing 7.2 Specifying category identity using IdClass
B Stored identity fields
public CategoryPK() {}
public boolean equals(Object other) {
if (other instanceof CategoryPK) {
final CategoryPK otherCategoryPK = (CategoryPK)other;
return (otherCategory.name.equals(name) &&
otherCategoryPK.createDate.equals(createDate));
}
return false;
}
public int hashCode() {
return super.hashCode();
}
}
@Entity
@IdClass(CategoryPK.class)
public class Category {
public Category() {}
@Id
protected String name;
@Id
protected Date createDate;
...
}
---------------------
1) i am unable to understand how this method works because inside the method public boolean equals(Object other), even i tried to put System.out.println, but when i checked the logs, this method was never called, so i want to understand, when this is used.
2) as the need for this method was for specifying the composite key's,
but even by using the first approach by using @Id on multiple instances work's i am able to see the composite keys in the database, so then why it is useful.