Skip to Content

Dynamic Calling of EJB

Hi,

I want to call an EJB in NetWeaver. I don't know the class of its Home Interface. I only know its JNDI name. So I use the following method.

1. Context context = new InitialContext();

2. Object home = context.lookup( name );

3. EJBHome ejbHome =(EJBHome) PortableRemoteObject.narrow (home, EJBHome.class);

But I got the exception "java.lang.ClassCastException: javax.ejb.EJBHome" when the program runs into 3.

I check the "home" variable, its type is "class com.sap.engine.interfaces.cross.ObjectReferenceImpl".

Could somebody tell me why this doesn't work? Is there any way to call an EJB when we don't know the Home Interface type and only know its JNDI name and the business method?

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on May 30, 2005 at 08:06 AM

    Hi Jerome

    For each enterprise bean, the EJB-jar file must include the following class files:

    1)Bean class

    2)Home and Remote Interfaces

    3)Primary key class, if the bean is an entity bean

    Context initialContext = new InitialContext();

    AccountHome accountHome = (AccountHome)

    javax.rmi.PortableRemoteObject.narrow(

    initialContext.lookup(“java:comp/env/ejb/accounts”),

    AccountHome.class);

    Sai

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Vesselin,

      Thanks a lot for the information. The caller is an EJB. As far as I know, one EJB cannot access classes of other EJB if the <ejb-ref> element of the caller's ejb-jar.xml is not set to be the called EJB. However, in our scenario, the called EJB is developed after the caller EJB is deployed to NetWeaver. So the caller cannot put the reference to the called EJB in its ejb-jar.xml file. So how can we make the classes of later-deployed EJB visible to the earlier-deployed EJB?

      Best Regards

      Jerome

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.