Hi and thanks in advance,
I have a EJBHomeFactory implemented that looks up homes by their interfaces' class names (and the ejb's are bound to these names indeed):
You may want to have a look at the lookup method posted at the bottom.
My problem is now that the narrow-method of PortableRemoteObject gives me a ClassCastException. I tested it through and through and found out that the Proxy returned from the JNDI-lookup does implement the interface I expect, but it is loaded from a different (sister-)classloader than my HomeFactory's classLoader, and thus, I cannot cast to my beloved home interface. Both is executed in a single JBoss EJB container instance, and the calling EJB has a ejb-local-ref entry to the looked up ejb in the ejb-jar.xml. Am I doing something wrong here?
public synchronized static EJBLocalHome lookupLocalEJBHome(Class ejbHomeClass) throws NamingException {
String jndiName = ejbHomeClass.getName();
//jndiNameToHomeObject is a hashMap instance
EJBLocalHome retVal = (EJBLocalHome) jndiNameToHomeObject.get(jndiName);
if (retVal == null) {
// initalizes the InitialContext
ensureInitialized();
Object objref = initialContext.lookup(jndiName);
retVal = (EJBLocalHome) PortableRemoteObject.narrow(objref, ejbHomeClass);
jndiNameToHomeObject.put(jndiName, retVal);
}
return retVal;
}
Many thanks for reading (and hopefully answering :),
Regards,
Armin