aspose file tools*
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
Author

EJB HELP

simon khor
Greenhorn

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.
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 ]
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
Greenhorn

Joined: Oct 02, 2002
Posts: 3
Dave,
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.
 
Consider Paul's rocket mass heater.
 
subject: EJB HELP