Hi All,
I have a BMP entity bean which contains findXXX method. This methods
returns Enumeration of the primary key object. when i am calling it from my
session bean and casting it to the remote reference i am geting
ClassCastException . I am giving the code snippet for the finder method
and the caller method. I am using websphere3.5 app. server.
Finder method. code
public Enumeration ejbFindByAllCriteria(int bookCategoryId, String title,
String author, String publisher) throws java.rmi.RemoteException,
javax.ejb.FinderException {
log("Inside findByAllCriteria method\n");
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
log("getting the connection object\n");
con = this.getConnection();
log("getting the Prepared Statement object\n");
//log("SQLSTRING: select * from SP_CATEGORY_DETAILS where User_Id = ?
and Sp_Category_Details = ?");
ps = con.prepareStatement("select Book_Id from BOOK where
Book_Category_Id = ? And Title like ? OR Author like ? OR Publisher like ?
");
ps.setInt(1, bookCategoryId);
ps.setString(2, title);
ps.setString(3, author);
ps.setString(4, publisher);
//log("Method argument userId: " + uKey.userId + " \n");
log("executing the prepared statement in ejbFindByAllCriteria\n");
rs = ps.executeQuery();
Hashtable hKey = new Hashtable();
//Vector keys = new Vector();
int i=0;
while(rs.next()) {
lafpackage.BookPK bookPk = new lafpackage.BookPK(rs.getInt(1));
//bookPk.bookId = rs.getInt(1);
// keys.addElement(bookPk);
hKey.put("pk"+i, bookPk);
i=i+1;
}
log("Before returning values "+hKey.size());
return hKey.elements();
} catch (SQLException e) {
log(e.getMessage());
throw new FinderException(e.getMessage());
} finally {
try {
if (ps != null)
ps.close();
if (con != null)
con.close();
} catch (SQLException e) {
log(e.getMessage() + "\n");
}
}
}
Caller method in session bean
public Vector searchBookDetails(int categoryId, String title, String
author, String publisher, PrintWriter out) throws RemoteException
{
Vector bookDetails = new Vector(10,5);
errLog("Before try block");
try {
errLog("Inside try block..");
Enumeration ebk =
bookHomeRef.findByAllCriteria(categoryId,title,author,publisher);
while(ebk.hasMoreElements())
{
errLog("Inside while block.. SearchSession\n");
Object bRef = ebk.nextElement();
errLog("bRef"+bRef.getClass());
book = (lafpackage.Book)bRef; //Exception occures here
errLog((lafpackage.Book)bRef;"after Book book =
(Book)ebk.nextElement()");
Vector row = book.getDetails();
errLog("afterVector row = book.getDetails()...");
bookDetails.addElement(row);
errLog("End of while block..");
}
errLog("Before returning book details..SearchSession");
return bookDetails;
}
catch(FinderException fe)
{
errLog("Finder Exception:"+fe.getMessage());
return null;
}
catch(Exception e)
{
errLog("Exception:"+e.getMessage());
e.printStackTrace(out);
return null;
}
}
Waiting for your valuable reply.
thanks
kumar
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".