Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8231973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:40:24+00:00 2026-06-07T17:40:24+00:00

I have a Stateful Session Bean (SFSB) which acts as authentication module. In the

  • 0

I have a Stateful Session Bean (SFSB) which acts as authentication module. In the SFSB I store the current user that is logged in. Moreover I have some facades (which are Stateless Session Beans (SLSB)) that handles the JPA/SQL stuff for my entities. In order to check the access permissions of the current user, I try to call the SFSB out of the SLSB. But the current user field is always “null” when called from SLSB. When calling the SFSB directly, the current user field is set correctly… For calling I use the @EJB annotation.

Any ideas what the problem might be? Is that somehow a context problem? Is it generally possible to call a SFSB from SLSB preserving it’s state?

Many thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T17:40:26+00:00Added an answer on June 7, 2026 at 5:40 pm

    You shouldn’t call a stateful session bean from a stateless session bean.

    Here is some reading: JEE6 Tutorial – Session Beans

    Stateless beans don’t know anything about your session. Any time you call it, it is stateless. Then it calls a stateful session bean. No surprise it doesn’t have any context relating to the state of the client’s session because it is called from stateless object.

    I don’t know if it will work, but you possibly could try to get the context by doing a JNDI lookup instead of DI using the @EJB notation. Something like this in the stateless ejb might work. You’ll probably have to play with it and I can’t guarantee anything. It should get the context of the client calling the stateless ejb. The client will need to have session context/scope or forget it.

    @Resource SessionContext sessionContext;
    
    MyStatefulBean msb = (MyStatefulBean)sessionContext.lookup("ejb/MyStatefulBean");
    msb.doSomething(fubar);
    

    It is better to call the stateful session bean from a client that has a session scope or from another stateful ejb. Stateless and stateful have different reasons for being.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a servlet code which invokes a stateful session bean code and increment
I have a stateful EJB that I am using to keep current user information
I have a servlet code which calls a ejb stateful session bean code as
Scenario: I have some @Statefull bean for user session (not an HTTP session, it
We currently have a Stateful bean that is injected into a Servlet. The problem
I have gone through various books on stateful and stateless session bean and how
I have some cleanup code which may try to refer to an (stateful) EJB
Seam advises using an Extended persistent context in a Stateful Session Bean, in order
I have a model that is stateful. In each state there are a selection
Is it possible to access a stateful session bean inside a stateless bean? My

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.