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.