i am using a the following as my
ejb design.
- EJB1.1
- session facade(stateless bean) -
transaction container..
- BMP.
- DAO.
The problem that i'm facing is ,i can't get the data from the collection in the session facade which i have store it in the DAO and return it to the BMP and then to session facade.
When the collection return to the BMP from DAO , i still able to retrieve the data from collection.
The problem here is when the BMP return the collection to the session fascade. It seem it fail to cast the object in the collection.
below is my code
================================
Session fascade (stateless bean)
================================
public ListModel getAllDetails(values) thorws FinderException {
try {
if(homeRef == null)
// basically this getReferences is use to get the refer to home.
getReferences();
Collection colResult = null;
colResult = homeRef.findOutAll(value);
java.util.Iterator i = colResult.iterator();
while (i.hasNext())
{
Object obj = (Object) i.next();
// START - fail here
System.out.println(" valuer - "+ (
String)obj) ;
//END - failhere
}
ListModel lpm= new ListModel(colResult);
return lpm;
} catch (FinderException fe) {
throw new FinderException(fe.getMessage());
} catch (RemoteException re) {
throw new EJBException(re);
}catch (ClassCastException css) {
System.out.println("Casting fail");
}
}
}
========
BMP
========
public Collection findOutAll(String value) throws javax.ejb.FinderException {
try{
// this to locate the DAO class inthe JNDI
ObjectDAO dao = getDAO();
Collection cl = dao.load("aaa");
Iterator i = cl.iterator();
while (i.hasNext())
{
Object obj = i.next();
System.out.println(" valuer - "+ (String)obj) ;
//All the record in the collection is list normally without casting error
}
return cl;
} catch (FinderException se) {
throw new FinderException (se.getMessage());
} catch (Exception acs) {
throw new EJBException(acs.getMessage());
}catch (ClassCastException css) {
System.out.println("Casting fail");
}
}
=====
DAO
=====
public Collection load(String value) throws exception
ResultSet result = null;
ArrayList arrList = new ArrayList();
result = stmt.executeQuery();
if ( !result.next() ) {
throw new Exception("No user found");
} else {
do {
arrList.add(new String(result.getString(1)));
} while (result.next());
}
} catch(SQLException se) {
throw new Exception("SQL fail")
} finally {
// this closeAll() use to close the connection
closeAll();
return arrList;
}
}
Thank in Advance
[ October 02, 2002: Message edited by: simon khor ]