Link to home
Start Free TrialLog in
Avatar of prateekkumar
prateekkumar

asked on

Error in create method on Home Interface!

Hi,
   I have made a somple stateless session bean and deployed on JRun4.0. While running the client I am getting error in calling crate method on home interface. The code is like this:

Context ctx          = getInitialContext();
 Object o = ctx.lookup("demo.DemoHome");
DemoHome dhome = (DemoHome)
               PortableRemoteObject.narrow(o, DemoHome.class);

Demo demo = dhome.create();//getting error here

The error is:

java.rmi.RemoteException: null; nested exception is:
        java.lang.NullPointerException
        at jrunx.cluster.ClusterAlgorithm.invokeService(ClusterAlgorithm.java:127)
        at jrunx.cluster.ClusterAlgorithm.invokeService(ClusterAlgorithm.java:80)
        at jrunx.rmi.Invocation.invoke(Invocation.java:302)
        at jrunx.rmi.RemoteInvocationHandler.invoke(RemoteInvocationHandler.java:177)
        at jrun.ejb.invocation.ClientInvocationHandlerImpl.invoke(ClientInvocationHandlerImpl.java:2
15)
        at $Proxy2.demoSelect(Unknown Source)
        at ejb.demo.DemoClient.main(DemoClient.java:58)
Caused by: java.lang.NullPointerException
        at jrun.ejb.interceptors.InvokerInterceptor.invokeObjectMethod(InvokerInterceptor.java:139)
Avatar of girionis
girionis
Flag of Greece image

Probably the "dhome" variable is null. Are you getting any other exceptions?
>  Object o = ctx.lookup("demo.DemoHome");

This lookup looks weird, you need to look for the EJB reference using the standard syntax:

java:comp/demo/DemoHome
Avatar of expertmb
expertmb

Lookup the bean using it's deployment id
have a look at
ejb-jar.xml

<ejb-name>Demo</ejb-name>
Avatar of prateekkumar

ASKER

The ejb-jar is like this:

<ejb-jar>
  <enterprise-beans>
    <session>
      <ejb-name>demo.DemoHome</ejb-name>
      <home>ejb.demo.DemoHome</home>
      <remote>ejb.demo.Demo</remote>
      <ejb-class>ejb.demo.DemoBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Container</transaction-type>
    </session>
  </enterprise-beans>

To add more about this question, I am getting these error when calling a method on "demo" object. I tried to print the objects and got these results:

DemoHome dhome = (DemoHome) PortableRemoteObject.narrow(o, DemoHome.class);
System.out.println("===========here1111==========" + dhome);//it is printing Demo.jar#demo.DemoHome

Demo demo = dhome.create();
System.out.println("===========here2222==========" + demo);// it is also printing Demo.jar#demo.DemoHome

// Here is the call that executes the method on the // server side object System.out.println("The result is " + demo.demoSelect());// here getting all those errors...
> <ejb-name>demo.DemoHome</ejb-name>

Try to change it to:

<ejb-name>DemoHome</ejb-name>

and access it like:

Object o = ctx.lookup("java:comp/DemoHome");

and tell us if this helps.

>> Demo demo = dhome.create();//getting error here

Shouldn't you be casting it too? Demo demo = ( Demo ) dhome.create () ;

Anyway, I don't think that dhome is null because the message says:

java.lang.NullPointerException
        at jrunx.cluster.ClusterAlgorithm.invokeService(ClusterAlgorithm.java:127)
> Shouldn't you be casting it too? Demo demo = ( Demo ) dhome.create () ;

It shouldn't, the create method returns an object of the home type anyway.
Hi girionis,
   I changed the ejb-name as DemoHome but the error is same.
>> It shouldn't, the create method returns an object of the home type anyway.

Yeah, you're right. Its been more than a year since I touched J2EE and have forgotten lots :-( unfortunately, this .NET thing that I'm being forced to work on doesn't suit me as I'd expected.

Prateek, can you post your updated XML?
ASKER CERTIFIED SOLUTION
Avatar of girionis
girionis
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I had something similar to this which worked:

<ejb-jar id="ejb-jar_ID">
      <display-name>wfejb</display-name>
      <enterprise-beans>
            <session id="FileMatchService">
                  <ejb-name>FileMatchService</ejb-name>
                  <home>com.citigroup.wfl.id.ejb.filematchservice.FileMatchServiceHome</home>
                  <remote>com.citigroup.wfl.id.ejb.filematchservice.FileMatchService</remote>
                  <ejb-class>com.citigroup.wfl.id.ejb.filematchservice.FileMatchServiceBean</ejb-class>
                  <session-type>Stateless</session-type>
                  <transaction-type>Container</transaction-type>
            </session>
      </enterprise-beans>
</ejb-jar>

FileMatchServiceHome objFileMatchServiceHome = ( FileMatchServiceHome ) ctx.lookup ( sJNDIName ) ;
FileMatchService objFileMatchService = ( FileMatchService ) objFileMatchServiceHome.create () ;
What is the "sJNDIName"'s value? Maybe it will give us some clues as to what is going wrong.
Well, it was "WFInd.FileMatchService".
ejb-jar-bnd.xmi:

<?xml version="1.0" encoding="UTF-8"?>
<ejbbnd:EJBJarBinding xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:ejbbnd="ejbbnd.xmi" xmlns:ejb="ejb.xmi" xmi:id="EJBJarBinding_1059548815063">
      <ejbJar href="META-INF/ejb-jar.xml#ejb-jar_ID"/>
      <ejbBindings xmi:id="EnterpriseBeanBinding_1059548815063" jndiName="WFInd.FileMatchService">
      <enterpriseBean xmi:type="ejb:Session" href="META-INF/ejb-jar.xml#RemoteInterface"/>
      </ejbBindings>
</ejbbnd:EJBJarBinding>
Hi,
   Finaly I am able to run this small EJB code..:) I don't know what exactly was wrong but I used this DD finally:

<!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN' 'http://java.sun.com/dtd/ejb-jar_2_0.dtd'>

<ejb-jar>
  <enterprise-beans>
    <session>
      <ejb-name>DemoHome</ejb-name>
      <home>ejb.demo.DemoHome</home>
      <remote>ejb.demo.Demo</remote>
      <ejb-class>ejb.demo.DemoBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Container</transaction-type>
    </session>
  </enterprise-beans>

  <assembly-descriptor>
    <container-transaction>
      <method>
        <ejb-name>DemoHome</ejb-name>
        <method-intf>Remote</method-intf>
        <method-name>*</method-name>
      </method>
      <trans-attribute>Required</trans-attribute>
    </container-transaction>
  </assembly-descriptor>

</ejb-jar>

Also I changed setSessionContext method from :
public void setSessionContext(SessionContext ctx) {    
    if (verbose)
      System.out.println("setSessionContext called");
    this.ctx = ctx;
    props = ctx.getEnvironment();
  }
 
To:
public void setSessionContext(javax.ejb.SessionContext ctx) {
    this.ctx = ctx;
  }


Thanks to all.