Forums Register Login

ClassCastException

+Pie Number of slices to send: Send
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)
+Pie Number of slices to send: Send
 

Collection reports = home.findAll();



Here you need to typecast home.findAll() returned value to Collection type that you are using in findAll() in home interface.

Collection reports = (CollectionTypeinHomeInterface)home.findAll();
+Pie Number of slices to send: Send
i have the home interface returning a Collection type already? I tried it anyway and i am still getting the class cast exception?
+Pie Number of slices to send: Send
hi

Finder Method returns the Collection of Remote Objects only

in the code

ReportDefinitionRemote remote = home.create();

here the Remote Object is ReportDefinitionRemote

home.findAll() returns the Collection of ReportDefinitionRemote objects only...

you cannot type cast to the other type ReportDefinitionPOJO

i hope this was the reason for error



He loves you so much! And I'm baking the cake! I'm going to put this tiny ad in the cake:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 470 times.
Similar Threads
Passing parameters between Session beans
Many-Many CMR -> link table not populating
JTable; Vectors & Boolean values
sorting in vectors
How can I pass vector in java?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 19:44:34.