Solved

Error in create method on Home Interface!

Posted on 2004-08-16
17
250 Views
Last Modified: 2013-11-24
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)
0
Comment
Question by:prateekkumar
  • 7
  • 5
  • 3
  • +1
17 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 11807743
Probably the "dhome" variable is null. Are you getting any other exceptions?
0
 
LVL 35

Expert Comment

by:girionis
ID: 11807765
>  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
0
 
LVL 6

Expert Comment

by:expertmb
ID: 11807797
Lookup the bean using it's deployment id
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 6

Expert Comment

by:expertmb
ID: 11807804
have a look at
ejb-jar.xml

<ejb-name>Demo</ejb-name>
0
 

Author Comment

by:prateekkumar
ID: 11808097
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...
0
 
LVL 35

Expert Comment

by:girionis
ID: 11808213
> <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.

0
 
LVL 30

Expert Comment

by:Mayank S
ID: 11808456
>> 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)
0
 
LVL 35

Expert Comment

by:girionis
ID: 11808464
> 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.
0
 

Author Comment

by:prateekkumar
ID: 11808992
Hi girionis,
   I changed the ejb-name as DemoHome but the error is same.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 11809116
>> 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?
0
 
LVL 35

Accepted Solution

by:
girionis earned 250 total points
ID: 11809143
What I suggest we do is to trace the error from the start. Can you do this and tell us the output:

Context ctx          = getInitialContext();
System.out.println("ctx: " + ctx);
 Object o = ctx.lookup("demo.DemoHome");
System.out.println("o: " + o);
DemoHome dhome = (DemoHome)
               PortableRemoteObject.narrow(o, DemoHome.class);
System.out.println("dhome: " + dhome);
Demo demo = dhome.create();//getting error here

0
 
LVL 30

Expert Comment

by:Mayank S
ID: 11809162
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 () ;
0
 
LVL 35

Expert Comment

by:girionis
ID: 11809187
What is the "sJNDIName"'s value? Maybe it will give us some clues as to what is going wrong.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 11809278
Well, it was "WFInd.FileMatchService".
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 11809292
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>
0
 

Author Comment

by:prateekkumar
ID: 11809391
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.
0
 
LVL 35

Expert Comment

by:girionis
ID: 11809445
:)
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question