Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Cast Exception from EJB returning Collection

843829Jul 26 2001 — edited Oct 30 2002
Still can't understand why I'm getting a cast exception when I call an object method when the object has been returned in a Collection from an EJB.

The object CountryModel is a serialised object, returned in a Collection from home.findAllCountries.....

I understood RMI returns the object in serialised form, why does called the CountryModel object method getCountryName() cause a ClassCast method? This object casting works ok for a non-rmi application.
 Collection boris = home.findAllCountries();
      Iterator i = boris.iterator();
      System.out.println( boris.size());              //gets right results

      while( i.hasNext()) {
        Object obj = i.next();
        CountryModel leModel = (CountryModel)obj;
        System.out.println(leModel.getCountryName());  //causes ClassCastException
      }
Any help appreciated. Thanks, lebo

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 27 2002
Added on Jul 26 2001
9 comments
136 views