File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes EJB HELP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB HELP" Watch "EJB HELP" New topic


simon khor

Joined: Oct 02, 2002
Posts: 3
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.
Collection colResult = null;
colResult = homeRef.findOutAll(value);
java.util.Iterator i = colResult.iterator();
while (i.hasNext())
Object obj = (Object);
// 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");

public Collection findOutAll(String value) throws javax.ejb.FinderException {
// 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 =;
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");

public Collection load(String value) throws exception
ResultSet result = null;
ArrayList arrList = new ArrayList();
result = stmt.executeQuery();
if ( ! ) {
throw new Exception("No user found");
} else {
do {
arrList.add(new String(result.getString(1)));
} while (;
} catch(SQLException se) {
throw new Exception("SQL fail")
} finally {
// this closeAll() use to close the connection
return arrList;

Thank in Advance
[ October 02, 2002: Message edited by: simon khor ]
Dave Landers
Ranch Hand

Joined: Jul 24, 2002
Posts: 401
In your Entity EJB implementation, the find method should be named ejbFindOutAll.
A BMP implementation of a finder will return a Collection of primary key objects. The container then converts these so that the finder method on the home interface returns a Collection of the Entity beans (remote interface).
Change your session bean to use:

You can then obtain the primary key using ejb.getPrimaryKey().
simon khor

Joined: Oct 02, 2002
Posts: 3
Thank very much for your solution. I really appreciate it. That really solve that problem, which is pending for 3 day. Actually i just a beginner on EJB. Just start doing research and study last month on EJB.
I agree. Here's the link:
subject: EJB HELP
It's not a secret anymore!