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.narro w(o, DemoHome.class);
Demo demo = dhome.create();//getting error here
The error is:
java.rmi.RemoteException: null; nested exception is:
java.lang.NullPointerExcep tion
at jrunx.cluster.ClusterAlgor ithm.invok eService(C lusterAlgo rithm.java :127)
at jrunx.cluster.ClusterAlgor ithm.invok eService(C lusterAlgo rithm.java :80)
at jrunx.rmi.Invocation.invok e(Invocati on.java:30 2)
at jrunx.rmi.RemoteInvocation Handler.in voke(Remot eInvocatio nHandler.j ava:177)
at jrun.ejb.invocation.Client Invocation HandlerImp l.invoke(C lientInvoc ationHandl erImpl.jav a:2
15)
at $Proxy2.demoSelect(Unknown Source)
at ejb.demo.DemoClient.main(D emoClient. java:58)
Caused by: java.lang.NullPointerExcep tion
at jrun.ejb.interceptors.Invo kerInterce ptor.invok eObjectMet hod(Invoke rIntercept or.java:13 9)
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.narro
Demo demo = dhome.create();//getting error here
The error is:
java.rmi.RemoteException: null; nested exception is:
java.lang.NullPointerExcep
at jrunx.cluster.ClusterAlgor
at jrunx.cluster.ClusterAlgor
at jrunx.rmi.Invocation.invok
at jrunx.rmi.RemoteInvocation
at jrun.ejb.invocation.Client
15)
at $Proxy2.demoSelect(Unknown
at ejb.demo.DemoClient.main(D
Caused by: java.lang.NullPointerExcep
at jrun.ejb.interceptors.Invo
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
This lookup looks weird, you need to look for the EJB reference using the standard syntax:
java:comp/demo/DemoHome
Lookup the bean using it's deployment id
have a look at
ejb-jar.xml
<ejb-name>Demo</ejb-name>
ejb-jar.xml
<ejb-name>Demo</ejb-name>
ASKER
The ejb-jar is like this:
<ejb-jar>
<enterprise-beans>
<session>
<ejb-name>demo.DemoHome</e jb-name>
<home>ejb.demo.DemoHome</h ome>
<remote>ejb.demo.Demo</rem ote>
<ejb-class>ejb.demo.DemoBe an</ejb-cl ass>
<session-type>Stateless</s ession-typ e>
<transaction-type>Containe r</transac tion-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.narro w(o, DemoHome.class);
System.out.println("====== =====here1 111======= ===" + dhome);//it is printing Demo.jar#demo.DemoHome
Demo demo = dhome.create();
System.out.println("====== =====here2 222======= ===" + 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-jar>
<enterprise-beans>
<session>
<ejb-name>demo.DemoHome</e
<home>ejb.demo.DemoHome</h
<remote>ejb.demo.Demo</rem
<ejb-class>ejb.demo.DemoBe
<session-type>Stateless</s
<transaction-type>Containe
</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.narro
System.out.println("======
Demo demo = dhome.create();
System.out.println("======
// 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</e jb-name>
Try to change it to:
<ejb-name>DemoHome</ejb-na me>
and access it like:
Object o = ctx.lookup("java:comp/Demo Home");
and tell us if this helps.
Try to change it to:
<ejb-name>DemoHome</ejb-na
and access it like:
Object o = ctx.lookup("java:comp/Demo
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.NullPointerExcep tion
at jrunx.cluster.ClusterAlgor ithm.invok eService(C lusterAlgo rithm.java :127)
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.NullPointerExcep
at jrunx.cluster.ClusterAlgor
> 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.
It shouldn't, the create method returns an object of the home type anyway.
ASKER
Hi girionis,
I changed the ejb-name as DemoHome but the error is same.
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?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I had something similar to this which worked:
<ejb-jar id="ejb-jar_ID">
<display-name>wfejb</displ ay-name>
<enterprise-beans>
<session id="FileMatchService">
<ejb-name>FileMatchService </ejb-name >
<home>com.citigroup.wfl.id .ejb.filem atchservic e.FileMatc hServiceHo me</home>
<remote>com.citigroup.wfl. id.ejb.fil ematchserv ice.FileMa tchService </remote>
<ejb-class>com.citigroup.w fl.id.ejb. filematchs ervice.Fil eMatchServ iceBean</e jb-class>
<session-type>Stateless</s ession-typ e>
<transaction-type>Containe r</transac tion-type>
</session>
</enterprise-beans>
</ejb-jar>
FileMatchServiceHome objFileMatchServiceHome = ( FileMatchServiceHome ) ctx.lookup ( sJNDIName ) ;
FileMatchService objFileMatchService = ( FileMatchService ) objFileMatchServiceHome.cr eate () ;
<ejb-jar id="ejb-jar_ID">
<display-name>wfejb</displ
<enterprise-beans>
<session id="FileMatchService">
<ejb-name>FileMatchService
<home>com.citigroup.wfl.id
<remote>com.citigroup.wfl.
<ejb-class>com.citigroup.w
<session-type>Stateless</s
<transaction-type>Containe
</session>
</enterprise-beans>
</ejb-jar>
FileMatchServiceHome objFileMatchServiceHome = ( FileMatchServiceHome ) ctx.lookup ( sJNDIName ) ;
FileMatchService objFileMatchService = ( FileMatchService ) objFileMatchServiceHome.cr
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_1059 548815063" >
<ejbJar href="META-INF/ejb-jar.xml #ejb-jar_I D"/>
<ejbBindings xmi:id="EnterpriseBeanBind ing_105954 8815063" jndiName="WFInd.FileMatchS ervice">
<enterpriseBean xmi:type="ejb:Session" href="META-INF/ejb-jar.xml #RemoteInt erface"/>
</ejbBindings>
</ejbbnd:EJBJarBinding>
<?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_1059
<ejbJar href="META-INF/ejb-jar.xml
<ejbBindings xmi:id="EnterpriseBeanBind
<enterpriseBean xmi:type="ejb:Session" href="META-INF/ejb-jar.xml
</ejbBindings>
</ejbbnd:EJBJarBinding>
ASKER
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-na me>
<home>ejb.demo.DemoHome</h ome>
<remote>ejb.demo.Demo</rem ote>
<ejb-class>ejb.demo.DemoBe an</ejb-cl ass>
<session-type>Stateless</s ession-typ e>
<transaction-type>Containe r</transac tion-type>
</session>
</enterprise-beans>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>DemoHome</ejb-na me>
<method-intf>Remote</metho d-intf>
<method-name>*</method-nam e>
</method>
<trans-attribute>Required< /trans-att ribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar>
Also I changed setSessionContext method from :
public void setSessionContext(SessionC ontext ctx) {
if (verbose)
System.out.println("setSes sionContex t called");
this.ctx = ctx;
props = ctx.getEnvironment();
}
To:
public void setSessionContext(javax.ej b.SessionC ontext ctx) {
this.ctx = ctx;
}
Thanks to all.
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-na
<home>ejb.demo.DemoHome</h
<remote>ejb.demo.Demo</rem
<ejb-class>ejb.demo.DemoBe
<session-type>Stateless</s
<transaction-type>Containe
</session>
</enterprise-beans>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>DemoHome</ejb-na
<method-intf>Remote</metho
<method-name>*</method-nam
</method>
<trans-attribute>Required<
</container-transaction>
</assembly-descriptor>
</ejb-jar>
Also I changed setSessionContext method from :
public void setSessionContext(SessionC
if (verbose)
System.out.println("setSes
this.ctx = ctx;
props = ctx.getEnvironment();
}
To:
public void setSessionContext(javax.ej
this.ctx = ctx;
}
Thanks to all.
:)