I am trying to use the findAll()method associated with an entity bean which returns a collection. I am then trying to store items in the collection in a vector but getting a classcastexception can anyone help please?
Code:
public Vector findAllReports()
{
Vector vect = new Vector();
//ReportDefinitionRemote remote = home.create();
try{
Collection reports = home.findAll();
System.out.println(reports + "in findAllReports()");
for (Iterator i = reports.iterator(); i.hasNext(); ) {
ReportDefinitionPOJO pojo = (ReportDefinitionPOJO)i.next();
vect.add(pojo);
}
}
catch(Exception e){throw new EJBException(e);}
return vect;
}
Error:
00:22:21,678 ERROR [LogInterceptor] EJBException in method: public abstract java
.util.Vector com.rgs.ejb.reportdefinitionmanager.ReportDefinitionManagerRemote.f
indAllReports() throws java.rmi.RemoteException, causedBy:
java.lang.ClassCastException
at com.rgs.ejb.reportdefinitionmanager.ReportDefinitionManagerBean.findA
llReports(ReportDefinitionManagerBean.java:134)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
Code:
public Vector findAllReports()
{
Vector vect = new Vector();
//ReportDefinitionRemote remote = home.create();
try{
Collection reports = home.findAll();
System.out.println(reports + "in findAllReports()");
for (Iterator i = reports.iterator(); i.hasNext(); ) {
ReportDefinitionPOJO pojo = (ReportDefinitionPOJO)i.next();
vect.add(pojo);
}
}
catch(Exception e){throw new EJBException(e);}
return vect;
}
Error:
00:22:21,678 ERROR [LogInterceptor] EJBException in method: public abstract java
.util.Vector com.rgs.ejb.reportdefinitionmanager.ReportDefinitionManagerRemote.f
indAllReports() throws java.rmi.RemoteException, causedBy:
java.lang.ClassCastException
at com.rgs.ejb.reportdefinitionmanager.ReportDefinitionManagerBean.findA
llReports(ReportDefinitionManagerBean.java:134)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)