Hello!
I have a function which queries all users from the database and prints their details, this function calls the line
Integer usrId=(Integer)((Vector)results.get(i)).get(0);
which converts the results set into vector, it gets a corresponding vector and gets the first element which corresponds to the id and then casts it as interger, but when i run it, this line gives errors like:
com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:540) [java] Caused by: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.util.Vector [java] at ejb.UserDirectory.printUsers(Unknown Source) [java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
Now i wonder how else can i implement this method? For it worked before and now its giving me errors. Please help.
Here is the complete code for the method:
public String printUsers(){ Query q = em.createNativeQuery("select id from EntityObject"); List results = q.getResultList(); String str=new String(); EntityObject msgUser; int i; for (i=0;i<results.size();i++) { Integer usrId=(Integer)((Vector)results.get(i)).get(0);// This line gives errors msgUser=em.find(EntityObject.class,usrId); str=str+msgUser.toStringShort()+"\n"; } return(str); }