[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Error in create method on Home Interface!

Posted on 2004-08-16
17
Medium Priority
?
260 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 1000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

649 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