Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

@IdClass EJB 3 in Action

 
Ranch Hand
Posts: 856
  • 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.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • 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: 856
  • 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
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please check this FAQ.
 
Amandeep Singh
Ranch Hand
Posts: 856
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh I read the faq now, will not do it in future.
 
Doe, a deer, a female deer. Ray, a pockeful of sun. Me, a name, I call my tiny ad ...
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic