Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem in accessing EJB Relationship mehod  RSS feed

 
Pras Tiwari
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am accessing the relationship methods in my entity bean in session bean as follows:-
=====================
public Collection getFeaturedparts(String ftr, String groupid, String subgroupid) throws EJBException{
Collection col=null;
Collection newCol=null;
Collection ppcol=null;
try {
col=pmlhome.findByfeatureditem("YES");
System.out.println("Collection got!!!");
} catch (FinderException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Iterator i=col.iterator();
PartsData pdata=null;
while(i.hasNext()){
//System.out.println("Collection"+i.next().toString());
pmlocal=(PartsMasterLocal)i.next();
try{
ppcol=pmlocal.getPartsPricing();
Iterator i1=ppcol.iterator();
while(i1.hasNext()){
pplocal=(PartsPricingLocal)i1.next();
if(pplocal.getGroupid()==groupid && pplocal.getSubgroupid()==subgroupid){
pdata.setPartmasterid(pplocal.getPartmasterid());
pdata.setListprice(pplocal.getListprice());
pdata.setDiscount((pplocal.getDiscount()));
}
}
}catch(NullPointerException e){
System.out.append("No entry for partmasterid"+pplocal.getPartmasterid()+"found in record!!!");
}
try{
pdlocal=pmlocal.getPartsDetail();
pdata.setDrawingno(pdlocal.getDrawingno());
pdata.setThumbnail(pdlocal.getThumbnail());
pdata.setMoq(pmlocal.getMoq());
pdata.setWeightunit(pmlocal.getWeightunit());
pdata.setPartid(pmlocal.getPartid());
pdata.setDescription(pmlocal.getDescription());
pdata.setDetaildesc(pmlocal.getDetaildesc());
System.out.println(pdlocal.getDrawingno());
newCol.add(pdata);
}
catch(NullPointerException e){
System.out.println("no record in detail foound for partmasterid="+pmlocal.getPartmasterbeanid()+"!!!");
}
pdata=null;
}
System.out.println("Got featured Products!!!");
System.out.println("Size of newCol="+newCol.isEmpty()); //I
//m getting error on this line
return newCol;
}
==========

But Problem is that when I access above method which should return collection from client file I m getting error as follows:-
==========
00:07:22,397 INFO [STDOUT] Got featured Products!!!
00:07:22,407 ERROR [LogInterceptor] RuntimeException in method: public abstract java.util.Collection econify.session.parts.interfaces.PartsSession.getFeaturedparts(java.lang.String,java.lang.String,java.lang.String) throws java.rmi.RemoteException:
java.lang.NullPointerException
at econify.session.parts.ejb.PartsSessionBean.getFeaturedparts(PartsSessionBean.java:283)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
============

Where is the problem???
Pls tell me .

Thanx in advance.

Prash
 
kalatta kalatta
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The explanation is you newCol collection is never intialized. Hence the NullPointerException.
 
Pras Tiwari
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

How to initialize th 'newCol' collection in my above method. Please tell me.
Thanx in advance.
Prash
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!