2 Replies Latest reply on May 17, 2011 7:45 AM by G K

    SFSB Problem - Saving data between methods invoking

    G K Newbie

      Hello Community,

       

      I am a beginner of J2EE and I try to learn it. After a lot of examples I read and programmed I dont understand the Stateful / Stateless SessionBean.

      I understand that stateful SB creates a own instance for every client and it can save so data for each client. I programmed a little programm which set a String called setUser (SFSB) and a method which returns the String (getUser).

       

      With a facade SLSB I try to invoke the method "setUser" from my stateful sessionBean. so far so good....but i added now a third stateless sessionbean called UserReader and tried to recieve the variable with the method getUser by Local Interface but my return value is everytime NULL but it is a SFSB!

       

      I cant find something in the internet that explains me...my stupid problem.

       

      I hope here are a lot of professionals of EJB3.0

       

      so far

       

      George

        • 1. SFSB Problem - Saving data between methods invoking
          jaikiran pai Master

          Can you please post your relevant code? That will help us in understanding the situation better.

          • 2. Re: SFSB Problem - Saving data between methods invoking
            G K Newbie

            Yes of course!

             

            SFSB - User

             

            package com.test;
            
            import javax.ejb.Stateless;
            
            /**
             * Session Bean implementation class User
             */
            @Stateful
            public class User implements UserRemote, UserLocal {
                String user = null;
                /**
                 * Default constructor. 
                 */
                public User() {
                    // TODO Auto-generated constructor stub
                }
            
                @Override
                public String getUser() {
                    // TODO Auto-generated method stub
                    return this.user;
                }
            
                @Override
                public void setUser(String user) {
                    // TODO Auto-generated method stub
                    this.user=user;
                }
            
            }
            

             

             

            SLSB - UserReader

             

             

            package com.test2;
            
            import javax.ejb.Stateless;
            
            import com.test.UserLocal;
            
            /**
             * Session Bean implementation class UserReader
             */
            @Stateless
            public class UserReader implements UserReaderRemote {
                @EJB(name="User") UserLocal uLocal;
                /**
                 * Default constructor. 
                 */
                public UserReader() {
                    // TODO Auto-generated constructor stub
                }
                @Override
                public void setUser(String user) {
                    // TODO Auto-generated method stub
                    uLocal.setUser(user);
                }
                @Override
                public String getUser() {
                    // TODO Auto-generated method stub
                    return uLocal.getUser();
                }
            
            
            
            }
            

             

            when i try to set and get this String via UserReaderRemote i can set it but i cant get it :O If I would create a third SessionBean and i would set with UserReaderRemote and want to get it with my third SB it wouldnt work, too

             

            Can you help me please?

             

            Can you follow me?