File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

@IdClass EJB 3 in Action

 
Amandeep Singh
Ranch Hand
Posts: 850
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Amandeep Singh
Ranch Hand
Posts: 850
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please check this FAQ.
 
Amandeep Singh
Ranch Hand
Posts: 850
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh I read the faq now, will not do it in future.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic