• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with ejbFindByPrimaryKey.  RSS feed

 
Praveen Dharmavaram
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can some one help me debug the problem with findByPrimaryKey.
I am getting a nullPointerException when i am trying to get the
findByPrimaryKey. I checked the key being passed on and it has the value
associated with it. I am also able to get to the home Interface. Any
thoughts why i get this exception.
Here is the sample code i have.
//Key
String key = "abc"
//Home
ABCHome abcHome =(ABCHome) new InitialContext().lookup("java:comp/env/ejb/ABC");
//Get the primary key
ABCKey abcKey = new ABCKey(key);
//find the primaryKey
ABC abc = (ABC) abcHome.findByPrimaryKey(abcKey);

Everything is fine until it gets to findByPrimaryKey and it throws a nullPointerException. I am unable to debug why it throws an nullPointerexception.Please help me.
Thanks
Praveen
 
Kalyan Ayyagari
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you missed a cast, try this:
ABCHome abcHome =(ABCHome) ((Context) (new InitialContext())).lookup("java:comp/env/ejb/ABC");
 
Praveen Dharmavaram
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont think thats the problem. I am still getting a null pointer exception after typecasting it.
Thanks for your help
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37181
515
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you check the JNDI name is the same as the one the EJB is registered as?
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Praveen,
If the line

is throwing a "NullPointerException", it means that "abcHome" must be null. However, you claim that "abcHome" is not null. This implies that the above line is not throwing a "NullPointerException". So perhaps if you posted your complete error message and stack trace, I may be able to help you further.
Good Luck,
Avi.
 
Vedhas Pitkar
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe this is a little bit naive,but have you checked the constructer of ABCKey ?
 
Praveen Dharmavaram
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here is the stack..I did use the debugger to find where the NullPointerException was being thrown and it was in one of the stubs.
Subscriber result = ((annap.sprint.ejb.server.subscriber.SubscriberHome)so.servant).findByPrimaryKey(arg0Copy);
The value of arg0Copy was not null and also the so.servant had value in it.

[8/4/03 16:31:29:797 EDT] 30238f9a ExceptionUtil E CNTR0019E: Non-application exception occurred while processing method "findByPrimaryKey". Exception data: java.lang.NullPointerException
at annap.sprint.ejb.server.subscriber.SubscriberBean.setEntityContext(SubscriberBean.java:2374)
at com.ibm.ejs.container.EntityBeanO.<init>(EntityBeanO.java:246)
at com.ibm.ejs.container.BeanManagedBeanO.<init>(BeanManagedBeanO.java:85)
at com.ibm.ejs.container.BeanManagedBeanOFactory.create(BeanManagedBeanOFactory.java:39)
at com.ibm.ejs.container.EJSHome.createBeanO(EJSHome.java:573)
at com.ibm.ejs.container.EJSHome.createBeanO(EJSHome.java:676)
at com.ibm.ejs.container.EJSHome.getFindByPrimaryKeyEntityBeanO(EJSHome.java:2317)
at annap.sprint.ejb.server.subscriber.EJSBMPSubscriberHomeBean_5a416d35.findByPrimaryKey(EJSBMPSubscriberHomeBean_5a416d35.java:70)
at annap.sprint.ejb.server.subscriber.EJSRemoteBMPSubscriberHome_5a416d35.findByPrimaryKey(EJSRemoteBMPSubscriberHome_5a416d35.java:59)
at annap.sprint.ejb.server.subscriber._SubscriberHome_Stub.findByPrimaryKey(_SubscriberHome_Stub.java:283)
at annap.sprint.server.request.VADRequest.getSubscriber(VADRequest.java:240)
at annap.sprint.server.request.WelcomeRequest.execute(WelcomeRequest.java:160)
at annap.sprint.server.servlet.RouterServlet.processRequest(RouterServlet.java:750)
at annap.sprint.server.servlet.RouterServlet.doPost(RouterServlet.java:212)
at annap.sprint.server.servlet.RouterServlet.doGet(RouterServlet.java:184)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:923)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:528)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:176)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:79)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:201)
at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:182)
at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:516)
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:362)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:593)
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thankyou Praveen, for providing the stack trace! Now your problem is crystal clear.
According to the stack trace you have posted, the "setEntityContext()" method in class "annap.sprint.ejb.server.subscriber.SubscriberBean" is throwing a "NullPointerException" -- specifically at line 2374 in file "SubscriberBean.java".
Of-course, since I didn't see the code for the "setEntityContext()" method in your post, again, there is no more that I can offer you. Now if you'd like to post the code, I may be able to offer something further.
(A bit like pulling teeth -- as they say in the classics!)
Good Luck,
Avi.
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Praveen,
Welcome to JavaRanch!! Please change your name to be compliant with JavaRanch's naming policy. It should not be obviously fictitious.
Your displayed name should be 2 separate names with more than 1 letter each. We really would prefer that you use your REAL name.
You can change your name: here.
Thanks,
Cindy
 
Alan Petersen
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd bet dollars to donuts that you forgot to define the ejb-ref in the deployment descriptor.
- alan
 
Praveen Dharmavaram
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well..then give me the dollars :-) I already checked that one and found that the ejb-ref were defined in the deployement descriptor. Apparantly as "Avi" pointed out that some thing might be wrong with the bean. I am trying to debug it and I could not find anything wrong with my code. May be I will get another pair of eyes to look at the code.
Thanks for all your help.
 
Alan Petersen
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's defined in WHICH deployment descriptor? If you zip up the code I'll take a look, but my bet is still that it's a deployment issue.
- alan
 
Alan Petersen
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Having reviewed the thread, I'd agree with Avi... I didn't look at the stack trace
I'm still willing to give the code a once-over if you want
- alan
 
Praveen Dharmavaram
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its defined in EJB Deployment Descriptor as well as Web Deployment Descriptor-References.Unfortunately i cant give out the actual code.
Thanks
 
Praveen Dharmavaram
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is entityContext.getEnvironment().getProperty a deprecated method in EJB 2.0. What is the alternative for it.
Thanks
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is entityContext.getEnvironment().getProperty a deprecated method in EJB 2.0. What is the alternative for it.

Yes, it is deprecated. As the javadoc for the deprecated javax.ejb.EJBContext#getEnvironment() says, you should use the JNDI naming context java:comp/env to access enterprise bean's environment.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!