[jboss-user] [EJB/JBoss] - Re: Fail to lookup entity bean inside a stateless session be

calsonli do-not-reply at jboss.com
Thu Jul 26 01:33:36 EDT 2007


Thanks a lot for your reply, Waynebaylor.

My lookup code is as follows, which is generated from XDoclet.


  | /**
  |  * Utility class for Staff.
  |  * @xdoclet-generated at ${TODAY}
  |  * @copyright The XDoclet Team
  |  * @author XDoclet
  |  * @version ${version}
  |  */
  | public class StaffUtil
  | {
  |    /** Cached local home (EJBLocalHome). Uses lazy loading to obtain its value (loaded by getLocalHome() methods). */
  |    private static ts.interfaces.StaffLocalHome cachedLocalHome = null;
  | 
  |    private static Object lookupHome(java.util.Hashtable environment, String jndiName, Class narrowTo) throws javax.naming.NamingException {
  |       // Obtain initial context
  |       javax.naming.InitialContext initialContext = new javax.naming.InitialContext(environment);
  |       try {
  |          Object objRef = initialContext.lookup(jndiName);
  |          // only narrow if necessary
  |          if (java.rmi.Remote.class.isAssignableFrom(narrowTo))
  |             return javax.rmi.PortableRemoteObject.narrow(objRef, narrowTo);
  |          else
  |             return objRef;
  |       } finally {
  |          initialContext.close();
  |       }
  |    }
  | 
  |    // Home interface lookup methods
  | 
  |    /**
  |     * Obtain local home interface from default initial context
  |     * @return Local home interface for Staff. Lookup using COMP_NAME
  |     */
  |    public static ts.interfaces.StaffLocalHome getLocalHome() throws javax.naming.NamingException
  |    {
  |       if (cachedLocalHome == null) {
  |             cachedLocalHome = (ts.interfaces.StaffLocalHome) lookupHome(null, ts.interfaces.StaffLocalHome.COMP_NAME, ts.interfaces.StaffLocalHome.class);
  |       }
  |       return cachedLocalHome;
  |    }
  | }
  | 

Thank you,
Calson

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4067675#4067675

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4067675



More information about the jboss-user mailing list