Problem with Session Beans state  
Author Message
dado0583





PostPosted: 2004-11-29 23:17:00 Top

java-programmer, Problem with Session Beans state Hi, I'm currently making a session bean, which will eventually act as
a Shopping Basket.

I have implemented the bean so that it just accepts a string (which
will eventually be an object reference), and the user can add and
remove strings.

Unfortunately, if I access the same bean from another machine and
create an instance of the session bean, they are shown the same
contents as from the other machine.

The session bean type is set to stateful (and I have tried stateless).
Can anyone point me in the direction of the problem please?

Cheers,
David
 
John C. Bollinger





PostPosted: 2004-11-30 0:45:00 Top

java-programmer >> Problem with Session Beans state Dj Frenzy wrote:

> Hi, I'm currently making a session bean, which will eventually act as
> a Shopping Basket.
>
> I have implemented the bean so that it just accepts a string (which
> will eventually be an object reference), and the user can add and
> remove strings.
>
> Unfortunately, if I access the same bean from another machine and
> create an instance of the session bean, they are shown the same
> contents as from the other machine.
>
> The session bean type is set to stateful (and I have tried stateless).
> Can anyone point me in the direction of the problem please?

First, you are probably using the wrong technology for what you're
trying to do. If you want to support a large number of concurrent
baskets then you want to maintain basket state either

(1) At the servlet level, in custom objects (possibly normal JavaBeans)
stored with (HTTP) session scope, or

(2) In a backend database, accessed via a stateless session bean or,
possibly, entity beans.

I would shoot for (1) if you can, as (IMO) EJBs are to be avoided except
where you _need_ their particular strengths (transactionality,
container-managed security, distributability, etc.). Where you need
EJBs, however, embrace them. Also, do not be confused by the name
"session bean" -- the "session" part is completely unrelated to the kind
of client sessions managed by the front end in a typical web application.


If you insist on carrying on with your current design then you may find
that clearing out the basket state in the bean implementation's
ejbRemove() method solves the immediate problem. If not, then, your
client interface is probably using the same session bean instance for
multiple clients (see above comments about sessions).


John Bollinger
email***@***.com
 
dado0583





PostPosted: 2004-11-30 19:43:00 Top

java-programmer >> Problem with Session Beans state Cheers John.

http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Session2.html

I found this this tutorial pretty helpful also.