| Author |
@IdClass EJB 3 in Action
|
Amandeep Singh
Ranch Hand
Joined: Jul 17, 2008
Posts: 837
|
|
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.
|
SCJP 1.4, SCWCD 5, SCBCD 5, OCPJWSD 5,SCEA-1, Started Assignment Part 2
My blog- http://rkydesigns.blogspot.com
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14672
|
|
I would be better if you'd stop posting the same question both here and at Manning's forum. (check this FAQ) [ November 16, 2008: Message edited by: Christophe Verre ]
|
[My Blog]
All roads lead to JavaRanch
|
 |
Amandeep Singh
Ranch Hand
Joined: Jul 17, 2008
Posts: 837
|
|
i need answer, so whereever i get it is better, is there any such problem to post at both forum's means Does i break any javaranch rule's,
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14672
|
|
|
Please check this FAQ.
|
 |
Amandeep Singh
Ranch Hand
Joined: Jul 17, 2008
Posts: 837
|
|
|
oh I read the faq now, will not do it in future.
|
 |
 |
|
|
subject: @IdClass EJB 3 in Action
|
|
|