EJB3: Passing a stateful bean to a stateless service

R

Rob Dennis

Hi,

we are currently designing a client-server system that is fixed (by
external factors) to use EJB3 at least for the client/server transport
layer. We use a lot of services that provide stateless methods, however
they require several "background/context" client-side parameters to do
their work. (A simple example would be login credentials, but there will
be more contextual data in the future, like user preferences.) This data
is mostly static within a client session, so we would like to avoid
passing it with every method call to the server.

The obvious approach seems to be to model the session data as a stateful
session bean. So far so good. But what is the proper way to access such
a stateful bean from a stateless service bean?

If possible, we would like to avoid having to pass an extra "session"
parameter with every method call. This would mean that each stateless
service needs to be able to look up session beans on its own. (Basically
we would need an utility class that provides a method like
"getContextData()" that automagically fetches the session bean for the
user that invoked the current stateless method.) Is this achievable in EJB3?

Alternatively, can you simply pass the client-side stub of a stateful
session bean as a method parameter? Is EJB smart enough to realize that
it does not need to serialize the stateful bean, as it is already
present on the server side? Or is there a way to get a "handle" for the
stateful session bean which can be passed as the method argument? How
can the stateless service use it to look up the session bean again?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top