Solved

Error in create method on Home Interface!

Posted on 2004-08-16
17
248 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
 
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:mayankeagle
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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:mayankeagle
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:mayankeagle
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:mayankeagle
ID: 11809278
Well, it was "WFInd.FileMatchService".
0
 
LVL 30

Expert Comment

by:mayankeagle
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now