wood burning stoves 2.0*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes @IdClass EJB 3 in Action Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "@IdClass EJB 3 in Action" Watch "@IdClass EJB 3 in Action" New topic
Author

@IdClass EJB 3 in Action

Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 844
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: 14688
    
  16

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: 844
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: 14688
    
  16

Please check this FAQ.
Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 844
oh I read the faq now, will not do it in future.
 
Don't get me started about those stupid light bulbs.
 
subject: @IdClass EJB 3 in Action