0 Replies Latest reply on Jun 16, 2004 2:49 PM by raf

    Update problems calling an entity bean from a session bean

    raf

      I'm facing strange update problems using an entity bean inside a session bean.
      Here is the scenario.

      I'm using JBoss 3.2.3
      I call an entity bean named TestBMPEntity mapping an existing record on the database with id=6
      from a session bean.


      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");


      // 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 first time I call this method from the client, it correctly updates the name on the the record in the database
      with primary key=6.
      The resulting System.out is (using name=pea):

      >first name: pea
      >id: 6


      If I make a second call of the method, (using name=pix), the resulting System.out doesn't change:

      >first name: pea
      >id: 6

      anyway I can find the record changed on the database with name=pix.
      The call on the session bean is not able to change the data in the entity, or at least to make that entity reload,
      but it updates the corresponding record on the database.

      Is it possible?

      Can anyone help me?