Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

casting problem

Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can we deal with getEJBHome () and getEJBObject () in EJBContext interface? I mean how can we cast the general EJBHome and EJBOjbect to the application specific EJB home reference and EJB object reference.

EJBHome ejbo = context.getEJBHome ();
CartHome ch = (CartHome) ejbo;
// or CartHome ch = (CartHome) PortableRemoteObject.narrow ( ch, CartHome.class );

How about the EJBObject?

Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jingyi,

No need to perform type-narrowing of the object received from EJBContext. The following is sufficient enough:

That is what the spec says in regards to SessionContext (same is applicable to EntityContext)

7.11.10 SessionContext

The container must implement the SessionContext.getEJBObject() method such that the
bean instance can use the Java language cast to convert the returned value to the session bean�s remote
interface type. Specifically, the bean instance does not have to use the PortableRemoteObject.
narrow(...) method for the type conversion.

Hope it helps
They weren't very bright, but they were very, very big. Ad contrast:
the value of filler advertising in 2020
    Bookmark Topic Watch Topic
  • New Topic