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

  • Home
  • SEARCH
  • 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 8249453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:33:00+00:00 2026-06-07T23:33:00+00:00

I do have a SessionScoped class. For each user access I need an own

  • 0

I do have a SessionScoped class. For each user access I need an own instance of this class. All went fine for a long time.
But now I also need access to this objects from the backend without any user interaction.
I do have a stateless enterprise bean but whenever I want to access the session scoped object I get an excepiton.
A simple example code is as following:

@SessionScoped
public class SessionObj implements Serializable {

    public String getValue() {
        return "Hello World";
    }
}

@Stateless
public class StatelessBean {

    private static final Logger LOG=Logger.getLogger(StatelessBean.class);

    @Inject
    private SessionObj sessionObj;

    public void test() {
        LOG.info("session object: "+sessionObj);
        LOG.info("Method call: "+sessionObj.getValue());
    }

}

But calling the test method ends in an exception like:

12:19:10,484 ERROR [org.jboss.as.ejb3.tx.CMTTxInterceptor] (EJB default - 6)    javax.ejb.EJBTransactionRolledbackException: WELD-001303 No active contexts for scope type javax.enterprise.context.SessionScoped
12:19:10,484 ERROR [org.jboss.ejb3.invocation] (EJB default - 6) JBAS014134: EJB Invocation failed on component StatelessBean for method public void package.StatelessBean.test(): javax.ejb.EJBTransactionRolledbackException: WELD-001303 No active contexts for scope type javax.enterprise.context.SessionScoped
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleInCallerTx(CMTTxInterceptor.java:139) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInCallerTx(CMTTxInterceptor.java:204) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:306) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:190) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
    ...
Caused by: org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active    contexts for scope type javax.enterprise.context.SessionScoped
    at org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:598) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
    at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:71) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
    at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:79) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
    at package.SessionObj$Proxy$_$$_WeldClientProxy.toString(SessionObj$Proxy$_$$_WeldClientProxy.java) [ws_core_job_manager.jar:]
    at java.lang.String.valueOf(String.java:2826) [rt.jar:1.6.0_21]
    at java.lang.StringBuilder.append(StringBuilder.java:115) [rt.jar:1.6.0_21]
    at package.StatelessBean.test(StatelessBean.java:29) [ws_core_job_manager.jar:]
    ...

So my question is:
* Is there any option to access the object even without a session by any trick?
* Is there any option to generate one session from within my stateless class?

I understand the cause of the exception but I want to have one ‘global’ session for this new usage of the existing code. In reallity of course it’s not so easy and changing the session scoped code to a POJO and a session scoped container is not so easy.

Environment:

  • JDK 1.6
  • JBOSS 7.1.1

Solution:

As mentioned by Jan:
Extend the StatelessBean as following:

@Stateless
public class StatelessBean {

    private static final Logger LOG=Logger.getLogger(StatelessBean.class);

    @Inject
    private BoundSessionContext sessionContext;

    @Inject
    private SessionObj sessionObj;

    public void test() {
        Map<String,Object> myMap=new HashMap<String,Object>();
        sessionContext.associate(myMap);
        sessionContext.activate();

        LOG.info("session object: "+sessionObj);
        LOG.info("Method call: "+sessionObj.getValue());

        sessionContext.invalidate();
        sessionContext.deactivate();
    }

}

And the example is working!
Now I just have to understand the details 😉

  • 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-07T23:33:02+00:00Added an answer on June 7, 2026 at 11:33 pm

    The problem is not to access to a session-scoped bean itself, the problem is that the session is not active, probably because it has never been started (e.g. EJB remoting).

    What you can do is starting a BoundSessionContext manually, have a look here. I did that for conversations, and it worked fine.

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

Sidebar

Related Questions

have written this little class, which generates a UUID every time an object of
I have a class : @SessionScoped public class LoggedUser { private User user; ...
i have my managed bean like this : @ManagedBean @SessionScoped public class utilisateur implements
I have a Session scoped bean @SessionScoped public class UserData implements Serializable { private
I have two beans. First bean languageOfSystem: @Named(value = languageOfSystem) @SessionScoped public class LanguageOfSystem
I have a Model: @Entity @Table(name = User) public class User implements Serializable {
I have a JSF 2.0 bean: @ManagedBean @SessionScoped public class LoginBean implements Serializable {
I have a managed bean called: @ManagedBean(name=configBean) @SessionScoped public class configBean implements Serializable {
In my application, I have the following beans: @Named(value = mrBean) @SessionScoped public class
I have a @SessionScoped @Named bean with a @Producer method for a user object:

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.