2 Replies Latest reply on Nov 30, 2006 4:34 AM by zzeuxis

    EJB 3 : stateful problem

    zzeuxis

      I'm trying to get a simple EJB 3.0 Stateful bean example working in JBoss.

      I've managed to get my example working using Stateless EJB :
      Simple Servet --> Stateless EJB --> retrieves some EJB Entity, saves a few bytes to the database and keeps a reference to the saved entity

      When the EJB is declared with a @Stateless decoration, everything seams to be working as expected : I see my log message in EJB initialization displayed everytime a new client connects.
      When I use @Stateful (which should be used since I want to maintain a reference to a session entity), I see that a new instance is created each time I access the EJB.

      Any idea what can be wrong ? (I can post my entire code if needed)

        • 1. Re: EJB 3 : stateful problem
          zzeuxis

          I forgot to mention I use (of course) Jboss 4.0.5 GA with the ejb3 profile selected from the installer

          • 2. Re: EJB 3 : stateful problem
            zzeuxis

            My best guess is that it's the way I call my bean from my jsf backing bean that's wrong : here is what I do :

             // constructor
             public MyJSFBackingBean() {
             this.bindJndiRessources();
             }
            
             private void bindJndiRessources() {
             Context context;
             try {
             context = new InitialContext();
             String beanName = StatefullBean.class.getSimpleName() + "/local";
             System.out.println("binding bean " + beanName);
             this.myBean = (StatefullInterface) context.lookup(beanName);
             } catch (NamingException e) {
             e.printStackTrace();
             }
             }