• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

primary key problem

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
i'm trying to deploy an entity bean in wl 5.0.
my primary key class appears like this
public class VProductPK implements java.io.Serializable {
public String productID;
public VProductPK(String productID) {
this.productID = productID;
}
public VProductPK() {
}
public String toString() {
return productID.toString();
}
public int hashCode()
{
return productID.hashCode();
}
public boolean equals(Object obj)
{
return((VProductPK)obj).productID.equals(productID);
}
}
logically i shouldn't be reqd to overload the equals and hashcode method
for a String primary ket but if i don't so i get an error at generation time
forcing me to put equals and hashcode method.
when i generate the jar i get an error in an class generated
at ..\ejbdeployer\provider-projects\product\ejb-jar\VProductBeanEOImpl.java
saying cannot convert string to productpk.
i.e it tries to compare a string and a class.
my ejb create method returns jas a return type of VProductPK and returns an instance
of the same.
if the ejbcreate method has a void return type i cannot
specify the type of primary key as VKProduct in the
deployer tool.
what could be the reason?
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Niki
I think rather than .equals use ==
return((VProductPK)obj).productID.equals(productID);
Use This
return((VProductPK)obj).productID.==productID);
I think this will solve ur problem
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well you should first check for the object type.
pkObj is the primary key class and pk is the primary key String class.
eg .
public boolean equals(Object obj)
{
if (Obj.instance of pkObj)
{
if(((pkObj)obj).pk.equals(pkobj.pk))
{
return true
}
else return false;
}
else return false;
}
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Double-check your nested parenthes - you're trying to return the object parameter casted to VProductPK.
mcd
 
reply
    Bookmark Topic Watch Topic
  • New Topic