CLASS CAST EXCEPTION
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Arun_Sista
Posted On:   Thursday, May 1, 2003 10:58 PM

The code below is my entity bean code... i have declared local and home interfaces.... there is another bean ProductBean which is also an entity bean.... When i call the getProduct()method internally in the bean in ejbCreate() it works perfectly... however when i try to call the getProduct() method thru the Local interface it gives me a class cast exception when i try to cast the result to a ProductLocal(LocalInterface) type: can anyone explain why this is happening....I have pointed out the part which gives the error.... public abstract class DealerBean implements EntityBean { protected EntityContext ctx; Collection products=null; javax.naming.Context context=null; ProductLocalHome productHome   More>>

The code below is my entity bean code... i have declared local and home interfaces.... there is another bean ProductBean which is also an entity bean....
When i call the getProduct()method internally in the bean in ejbCreate() it works perfectly... however when i try to call the getProduct() method thru the Local interface it gives me a class cast exception when i try to cast the result to a ProductLocal(LocalInterface) type: can anyone explain why this is happening....I have pointed out the part which gives the error....



public abstract class DealerBean implements EntityBean
{
protected EntityContext ctx;
Collection products=null;
javax.naming.Context context=null;
ProductLocalHome productHome=null;
ProductLocal product=null;
public DealerBean(){}
public abstract String getName();
public abstract void setName(String name);
public abstract String getDescription();
public abstract void setDescription(String description);
public abstract String getDealerID();
public abstract void setDealerID(String DealerID);
public void getProducts()
{getProduct();}
public void getProduct()
{
try
{
System.out.println("has entered this loop:**************");
//product=productHome.create("1238-219-10-2112","washing powder","this is a washing powder",5400,this.getDealerID());
Iterator i=productHome.findByDealerID("122-32").iterator();
while(i.hasNext())
{
product=(ProductLocal)i.next();
/***************************************************/
/***** this part gives class cast exception****************/
/*********when called from local interface/
System.out.println("Inside the getProduct method");
System.out.println(product.getBasePrice());
}
}catch(Exception e)
{
System.out.println("Error in getProducts():"+e);
}

}


public void ejbActivate()
{
System.out.println("ejbActivate() dealer called.");

}
public void ejbRemove()
{
System.out.println("ejbRemove() dealer called.");
}
public void ejbPassivate()
{
System.out.println("ejbPassivate() dealer called.");
}
public void ejbLoad()
{
System.out.println("ejbLoad() dealer called.");
}
public void ejbStore()
{
System.out.println("ejbStore() dealer called.");
}
public void setEntityContext(EntityContext ctx)
{

System.out.println("setEntityContext() dealer called.");
}
public void unsetEntityContext()
{
System.out.println("unsetEntityContext dealer called");
}
public void ejbPostCreate(String DealerID, String name, String description)
{
System.out.println("ejbPostCreate() dealer called.");
}

public DealerPK ejbCreate(String DealerID, String name, String description)throws CreateException
{
try
{
context=new javax.naming.InitialContext();
}catch(Exception e)
{
System.out.println("Error in setEntityContext()while creating context:"+e);
}
Object obj=null;
try
{
obj=context.lookup("java:comp/env/ejb/MyProductLocalHome");
}catch(Exception e)
{
System.out.println("Exception in setEntityContext while looking up the ProductHome:");
}
productHome=(ProductLocalHome)obj;
System.out.println("constructor dealer called:");

System.out.println("ejbCreate() dealer called");
setDealerID(DealerID);
setName(name);
setDescription(description);
DealerPK prod=new DealerPK(DealerID);
product=productHome.create("1237-219-10-2112","washing powder","this is a washing powder",2400,this.getDealerID());
getProduct();
/***************************************************/
/********* getProduct()WORKS PROPERLY HERE****************/
return prod;

}

}

   <<Less

Re: CLASS CAST EXCEPTION

Posted By:   Simon_Ablett  
Posted On:   Friday, May 2, 2003 04:29 AM

Please post large code chunks between
 and 
tags. It makes it easier to read.

Regards
About | Sitemap | Contact