2 Replies Latest reply on Jun 23, 2004 3:21 AM by raf

    Entity bean called from a session bean or directly from a cl

    raf Newbie

      I am using jboss 3.2.3.
      Scenario:
      I have an entity bean (BMP) with setX(String value) and getX() methods.
      I call it from a session bean SB and from a client CL.


      1)I call setX(v1) from SB
      2)I call getX() from SB and obtain v1
      3)I call setX(v2) from SB
      4)I call getX() from SB and obtain v2
      5)I call getX() from CL and obtain v1

      It seems that the client and the session bean are managing two different instances of the bean.
      Possible?

        • 1. Re: Entity bean called from a session bean or directly from
          Heiko Rupp Master

          What is your transaction demarcation?
          Are 3 and 4 executed in the same call to the SB and 5 before the call to this SB returns?

          • 2. Re: Entity bean called from a session bean or directly from
            raf Newbie

            3 and 4 executed in the same call to the SB but 5 is executed after the call to this SB returns.

            I'm using the following client code:

            ===============================================

            ..........

            InitialContext lContext = new InitialContext();

            TestSessionHome lHome = (TestSessionHome) lContext.lookup( "ejb/TestSession" );
            TestSession lSession = lHome.create();
            // Get a new Id of the Test Entity

            lSession.updateEntity(6,"pea");

            lSession.updateEntity(6,"pix");

            // Get Test Entity Remote Interface
            //Context lContext = new InitialContext();

            TestBMPEntityHome lHomeEntity = (TestBMPEntityHome) PortableRemoteObject.narrow(
            lContext.lookup(
            "ejb/TestBMPEntity"
            ),
            TestBMPEntityHome.class
            );

            TestBMPEntityPK pk=new TestBMPEntityPK(6);
            TestBMPEntity lEntity = lHomeEntity.findByPrimaryKey(pk);
            TestBMPEntityData lDataEntity =lEntity.getValueObject();

            System.out.println("first name: "+lDataEntity.getFirstName());
            System.out.println("id: "+lDataEntity.getId());


            ===============================================

            this is the called session bean method:

            ===============================================


            /**
            * @ejb:interface-method view-type="remote"
            **/
            public void updateEntity(int id, String name)
            throws
            RemoteException
            {
            try {
            // Get Test Entity Remote Interface
            Context lContext = new InitialContext();

            TestBMPEntityHome lHome = (TestBMPEntityHome) PortableRemoteObject.narrow(
            lContext.lookup(
            "ejb/TestBMPEntity"
            ),
            TestBMPEntityHome.class
            );
            TestBMPEntityPK pk=new TestBMPEntityPK(id);
            TestBMPEntity lEntity = lHome.findByPrimaryKey(pk);
            TestBMPEntityData lData = new TestBMPEntityData();
            //lEntity.getValueObject();


            lData.setFirstName(name);
            lData.setId(id);

            lEntity.setValueObject(lData);

            }
            catch ( Exception ive ) {
            throw new EJBException( "exception: " + ive.getMessage() );
            }

            }
            ===============================================


            The resulting System.out is (using v1=pea):

            >first name: pea
            >id: 6



            anyway I can find the record changed on the database with name=pix.