• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

EJB HELP

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic