I think what you're trying to do is a singleton.  In that case, use BMP
and always return the same key, i.e., "".  I use this for holding Home
Interface
Contexts for EJB's that other EJB's use.

public class HomeBrokerEJB implements EntityBean
{
    transient Hashtable table_;
    transient EntityContext context_;
    transient Context namingContext_;

    public String ejbCreate(String key)
    {
        return "";
    }

    public String ejbFindByPrimaryKey(String key)
        throws RemoteException, FinderException
    {
        try
        {

            if(namingContext_ == null)
                ejbActivate();
        } catch (Exception e)
        {
            throw new RemoteException("Unable to create singleton.", e);
        }
        return "";
    }
...
}


-----Original Message-----
From: Pedro Garcia Lopez [mailto:[EMAIL PROTECTED]]
Sent: Friday, June 02, 2000 7:34 AM
To: Orion-Interest
Subject: Maintaining state: EJB question


Hi,

In order to maintain state for multiple clients the EJB specification
recommends the use of Entity Beans.
So you need to use a database even if you want to maintain state that is
not persistent.

I have found a solution that I do not know if it is correct:
I use a Session Bean.
I the ejbCreateMethod of the Session BEan I do this:

  public void ejbCreate(String name)
  {

   this.name = name;
   users = new HashMap();
  try{
   EJBObject ref = context.getEJBObject();
   Context initial = new InitialContext();

  initial.bind(name,ref);
  }catch (javax.naming.NamingException ex){
   ex.printStackTrace();
  }
   }


and then, applicatrion clients can use JNDI to connect to the Session
Bean reference. You can thus maintains state for multiple clients using
a Session Bean.

Is this a bad trick ?

Some guy told me that this is dangerous due to activation and
passivation, but I think that documentation says that getEjbObject gives
you a handle that persists acrosts passivations states.

Let me know your comments.

In CORBA the Naming service is also used for locating references to
specific instance of remote objects.
In the EJB model I have seen that JNDI is used for locaintg factory
objects (Home).

Is this approach correct ?
can JNDI also be used for locating specific instances ?

Thank you in advance.


Reply via email to