• Post Reply Bookmark Topic Watch Topic
  • New Topic

Caching remote ejbobject  RSS feed

 
Sandeep Lodhia
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Our application,we have only stateless session bean.Hence we r caching remote ejbobject.
So the code for it is as follows :
public EJBHome getHome(String jndiHomeName, Class className) throws Exception
{
EJBHome home = null;
try{
Context initialContext = null;
Object objref = null;
try
{
initialContext = new InitialContext(System.getProperties());
objref = initialContext.lookup(jndiHomeName);
}
catch(Exception localExcep)
{
//code for exception
}
home = (EJBHome)PortableRemoteObject.narrow(objref, className);
}
catch (NamingException ne)
{
throw new MyOnstarSystemException(ne);
}
catch (Exception e)
{
throw new MyOnstarSystemException(e);
}

return home;
}
The problem is, above method returns EJBHome and not specific bean home.So i cant call create() on EJBHome.I need to have specific home say, AdminHome.
So how can I get specific home in generic way !!!
1 solution is, according to jndiHomename passed as method parameter, i create specific home object.
Pls let me know if there is any other solution.
Thanks.
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your client code you need to explicitly cast the result of a call to getHome() into your specific EJBHome type. The code would look similar to:
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!