• 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

java.lang.ClassCastException

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi...

i have made bmp bean when i try to run the following method(ejbFindByFirstName()) from the client side it will give me the following error.here i am sending u client code ,menthod and a class which i am using

------------------
java.lang.ClassCastException: EmpEntityBean_xzbwyf_EOImpl_WLStub
at ConnectClient.go(ConnectClient.java:50)
at ConnectClient.main(ConnectClient.java:13)
---------------
public Collection ejbFindByFirstName(String lFirstName) throws FinderException
{
PreparedStatement pstmt = null;
Connection conn = null;
ResultSet result = null;
ReturnVector rv=new ReturnVector();

try
{
conn = this.getConnection();
System.out.println("ejbFindByFirstName(" + lFirstName + ") called");

pstmt = conn.prepareStatement("SELECT EMPID,EMPFIRSTNAME,EMPLASTNAME FROM EMPDATA WHERE EMPFIRSTNAME = ?");

pstmt.setString(1, lFirstName);
result = pstmt.executeQuery();
Vector keys=new Vector();

System.out.println("Before while in findbyfirst name");
while (result.next())
{
System.out.println("in while findbyfirst name");
System.out.println(result.getInt("EMPID"));
System.out.println(result.getString("EMPFIRSTNAME"));
System.out.println(result.getString("EMPLASTNAME"));

rv.EmpId=result.getInt("EMPID");
rv.FirstName=result.getString("EMPFIRSTNAME");
rv.LastName=result.getString("EMPLASTNAME");
keys.addElement(rv);
}
System.out.println("After while in findbyfirst name");
return keys;
}
catch (Exception e)
{
throw new FinderException(e.toString());
}
finally
{
try { if (pstmt != null) pstmt.close(); }
catch (Exception e) {}
try { if (conn != null) conn.close(); }
catch (Exception e) {}
}

}

----------------------
import java.io.Serializable;
public class ReturnVector implements java.io.Serializable
{
int EmpId;
String FirstName;
String LastName;
}
---------------------
client code
--------------------------
Collection c = home.findByFirstName("hello");

Vector v=new Vector(c);;
ReturnVector rv=(ReturnVector)v.firstElement(); // error is here
System.out.println(rv.EmpId);
System.out.println(rv.FirstName);
System.out.println(rv.LastName);

-------------------------

my ejbFindByFirstName() method returning a vector which contain the object of class ReturnVector. i used this class be becoz i want to return multiple values form method.plz help me out how can i solve this problem. i also want to know that if my method returning multiple records how i can i get from the client side...


in my above problem in find method returning vector contain object of RetunVector class. if my returning vector contain string or int then from the client if i access then there is not any error but it will print following

EmpEntityBean_xzbwyf_EOImpl_WLStub

i didnot understand what this is all about

plz help me to solve this problem.....

regards
amit grover
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would like to point you at Section 10.7.3 of the EJB 2.0 spec, which states:


The return type of a finder method must be the entity bean�s primary key type, or a collection of primary keys.



Which means that the collection you are returning does not contain the expected object types. Unless you declare ReturnVector as being the primary key class (10.6.13) of your bean, your code won't work...
reply
    Bookmark Topic Watch Topic
  • New Topic