EJB3: Passing a stateful bean to a stateless service

Discussion in 'Java' started by Rob Dennis, Apr 1, 2008.

  1. Rob Dennis

    Rob Dennis Guest

    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?
    Rob Dennis, Apr 1, 2008
    #1
    1. Advertising

  2. Rob Dennis

    JThangiah Guest

    Hi Rob,
    I am researching for a very similar question and came across your
    posting. I am new to this too, but I found an article which might help
    you.
    <http://www.onjava.com/pub/a/onjava/2005/02/23/ejbpattern.html>

    This talks about the 'On-Demand Stateful EJBs' design pattern. Hope it
    helps a bit.
    Cheers,
    Jeyanthi
    JThangiah, Apr 14, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. davout
    Replies:
    1
    Views:
    787
    John C. Bollinger
    Dec 11, 2003
  2. Rudolf
    Replies:
    0
    Views:
    665
    Rudolf
    Jun 1, 2004
  3. harry
    Replies:
    4
    Views:
    7,821
    harry
    Nov 26, 2004
  4. Replies:
    7
    Views:
    7,552
    Andrea Desole
    Aug 8, 2005
  5. nospam
    Replies:
    8
    Views:
    35,913
    Nsikak Eka
    Feb 24, 2011
Loading...

Share This Page