• 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

ClassCastException in all finder methods != findByPK

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Horaci Macias
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic