I am migrating an application from JBoss 4.0.4 to JBoss 6.1. There is a jar that has some version 2.1 EJBs. One of the session beans has a static initializer that looks up an entity bean. That works ok in 4.0.4 but gives this error when starting JBoss 6.1 - "javax.naming.NameNotFoundException: mymod not bound".
static
{
MyEntityBeanLocalHome lhpt = MyEntityBeanUtil.getLocalHome();
Collection things = lhpt.findAll();
populate a static HashMap with things
}
The exception is thrown at the getLocalHome line above, which does the following:
InitialContext ic = new InitialContext(null);
Object objRef = ic.lookup("ejb/mymod/MyEntityBeanLocal"); <-- fails here
if (java.rmi.Remote.class.isAssignableFrom(MyEntityBeanLocalHome.class))
return javax.rmi.PortableRemoteObject.narrow(objRef, MyEntityBeanLocalHome.class);
else
return objRef;
I am a little surprised the jar deployed ok in JBoss 4.0.4 - after all, why should the entity bean have been bound to JNDI at the point the original coder tried to look it up?
But I would like some opinions on what is the best way to resolve this issue please. The session bean is stateless so moving the static code to an ejbActivate is not an option. I'm thinking of just creating a POJO that is accessed from the business method of the session bean and getting that POJO to retrieve the entities (one time only).
Thank you for any useful input.
Paul