| Author |
ClassCastException in all finder methods != findByPK
|
Horaci Macias
Ranch Hand
Joined: Nov 08, 2001
Posts: 74
|
|
I'm testing my EJB finder methods and I've problems in all of them except findByPK. A exception is thrown when I try to cast the Enumeration return findBy... to my EJB's remote interface. It's strange because if I debug my ejbFindBy... it works fine; the return Enumeration has all PK that have to be there, but if I try to cast to my EJB's remote interface after calling findBy... (in home interface) it crashes like this: java.lang.ClassCastException: org.omg.stub.javax.ejb._EJBObject_Stub If used Class.isAssignableFrom(Class) and the objects in return Enumeration aren't assignable to my remote interface nor my ejb class nor to my home interface ?!  I'm using WAS 3.5 Advanced Edition. Could anyone help me please ? Thank you, Horaci Macias
|
 |
Kyle Brown
author
Ranch Hand
Joined: Aug 10, 2001
Posts: 3878
|
|
Yeah, this is a bug (actually, it's an "alternate interpretation of a vague area of the EJB 1.0 spec" -- in other words a bug). What you need to do is do a javax.rmi.PortableRemoteObject.narrow() on each of the objects returned like so: Enumeration enum = myFooHome.findAllFoos(...); while (enum.hasMoreElements()) { Object ref = enum.nextElement(); FooEJB ejb = (FooEJB) javax.rmi.PortableRemoteObject.narrow(ref, FooEJB.class); // you can now use the ejb object... } Kyle ------------------ Kyle Brown, Author of Enterprise Java (tm) Programming with IBM Websphere See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.
|
Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
|
 |
Horaci Macias
Ranch Hand
Joined: Nov 08, 2001
Posts: 74
|
|
Thank you again Kyle. The solution you gave me makes everything work fine, the only problem I had is that when you said: FooEJB ejb = (FooEJB) javax.rmi.PortableRemoteObject.narrow(ref, FooEJB.class); I thought you meant FooEJB -> EJB class, and it did'nt work at first (another ClassCastException in narrow()). Later I try to use my remote interface instead of my ejb class and narrow() worked fine. Thank you, Horaci Macias
|
 |
 |
|
|
subject: ClassCastException in all finder methods != findByPK
|
|
|