At 01:20 PM 10/11/00 -0400, you wrote:
>Sorry for the newbie question...
>
>In the business methods in my stateless session beans I've always done what 
>seems like the usual pattern - lookup and narrow entity bean home 
>interfaces in the method that uses them.  However, to save some time, I'd 
>like to do these lookups in the SLSB's ejbCreate method and save them in 
>instance variables.
>
>I've rtfm, along with RMH, and can't see a reason why this wouldn't work, 
>both with Orion and portably.  Have I missed something?

Yes. Table 3 of EJB1.1 spec doesn't say that enterprise bean access is
available from the ejbCreate method of a stateless session bean. (Hence it
isn't.)

>Better yet, can these be put into a class field and only looked once, 
>rather than every bean instance.  For example
>
>private static BeanHome beanhome = null;
>...
>ejbCreate()
>   {
>   ...
>   if(beanhome == null)
>     {
>     beanhome = (lookup/narrow beanhome... )
>     }
>  ...
>   }
>

I don't see why not, so long as you don't try to populate them from
ejbCreate.  Why not use a getBeanHome() method which acts as a cache? ie

private static BeanHome beanhome = null;
private BeanHome getBeanHome(){
        if( beanhome==null ) .....set the variable
        return beanhome;
}

I believe that there could conceivably be more than one instance of this
static variable in a distributed application (multiple VM's) but
nevertheless I don't see a problem with this solution.

Nick

Reply via email to