on 07-27-2009 12:13 PM
Hello all,
I have Entity and Stateless Session Beans working properly once tested via web services. And I created a command bean to call the methods.
The SessionBean returns a wrapper class array.
ClassCastException's here: temp_record = (BusinessUnitLocal) itr.next(); // CLASS CAST EXCEPTION
What are the possible issues that I need to look into to fix this?
Please help. Thank you.
Here's my commandbean declaration:
private BusinessUnitSessionLocal localBUnit = null;
private BusinessUnitSessionLocalHome localHomeBUnit = null;
try{
localHomeBUnit = (BusinessUnitSessionLocalHome) icontext.lookup(
"localejbs/BusinessUnitSessionBean");
localBUnit = localHomeBUnit.create();
}catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (CreateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//method call
public void findAllBusinessUnit() {
Collection records = new ArrayList();
BusinessUnitWrapper record = null;
BusinessUnitLocal temp_record = null;
records = new ArrayList(Arrays.asList(localBUnit.findAll()));
Iterator itr = records.iterator();
while (itr.hasNext()) {
*temp_record = (BusinessUnitLocal) itr.next(); // CLASS CAST EXCEPTION*
record = new BusinessUnitWrapper();
record.setBusinessUnitID(temp_record.getBusinessUnitID());
record.setBusinessUnitName(temp_record.getBusinessUnitName());
record.setBusinessUnitStatus(temp_record.getBusinessUnitStatus());
outputBUnit.add(record);
}
}
Hi JMJ
Check implementation of BusinessUnitSession bean, method findAll(). What does the method actually return? It should be array of entity beans.
BR, Sergei
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Sergei,
Thank you for the prompt response.
Here's my code for the findAll method:
public BusinessUnitWrapper[] findAll() {
ArrayList buList = new ArrayList();
Collection val = null;
BusinessUnitWrapper buWrapper = new BusinessUnitWrapper();
try {
val = localHome.findAll();
for (Iterator iterator = val.iterator(); iterator.hasNext();) {
BusinessUnitLocal data = (BusinessUnitLocal) iterator.next();
buWrapper = convertToBUWrapper(data);
buList.add(buWrapper);
}
//TicketWrapper[] result = new TicketWrapper[tickets.size()];
//tickets.toArray(result);
BusinessUnitWrapper[] result =
new BusinessUnitWrapper[buList.size()];
buList.toArray(result);
return result;
} catch (FinderException ex) {
ex.printStackTrace();
}
return null;
}
User | Count |
---|---|
89 | |
10 | |
9 | |
9 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.