• Post Reply Bookmark Topic Watch Topic
  • New Topic

primary key problem

 
nikita kale
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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?
 
sachin sachdeva
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • 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
 
Prashant Jani
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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;
}
 
mcd
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Double-check your nested parenthes - you're trying to return the object parameter casted to VProductPK.
mcd
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!