0 Replies Latest reply on Nov 29, 2002 4:22 AM by georges

    Can't update an entity bean oout of a servlet

    georges

      Hi all!

      I get a strange behaviour of an entity bean in JBoss 2.4.1a. The problem is that I want to update an entity bean. I wrote a System.ou.t println in the setter-Method of this bean. The value is correct, but if I read this value with the getter-Method the old value is returned. The strange thin is, from my app-client everything works fine. Any hints about that.

      The Bean is like that

      public class UserBean implements EntityBean
      {
      protected EntityContext entityContext;

      //primaryKey fields
      public String client;
      public String userid;

      //mandatory fields
      public String password;

      //optional fields
      public Date pwduration;
      public String loginattempts;



      public UserBeanPK ejbCreate(BeanData data) throws CreateException
      {
      // Objektstatus setzen
      this.client= data.getStringAttribute("client");
      this.userid= data.getStringAttribute("userid");

      this.password= data.getStringAttribute("password");

      return null;
      }

      public void ejbPostCreate(BeanData data){}
      public void ejbActivate() {}
      public void ejbLoad() {}
      public void ejbPassivate() {}
      public void ejbRemove() throws RemoveException {}
      public void ejbStore() {}
      public void setEntityContext(EntityContext ctx) {
      // Keep the entity context in object
      entityContext = ctx;
      }
      public void unsetEntityContext() {
      entityContext = null;
      }

      /*========================= User implementation ============================*/

      public void setUserData(BeanData data)
      {
      this.password= data.getStringAttribute("password");

      this.pwduration= data.getDateAttribute("pwduration");
      loginattempts= data.getStringAttribute("loginattempts");
      System.out.println("beanset"+loginattempts);
      }

      public BeanData getUserData()
      {
      System.out.println("beanget"+loginattempts);
      BeanData data = new BeanData();
      //Primary fields
      data.setStringAttribute("client",client);
      data.setStringAttribute("userid",userid);

      //Mandatory fields
      data.setStringAttribute("password",password);

      //Optional fields
      data.setDateAttribute("pwduration",pwduration);
      data.setStringAttribute("loginattempts",loginattempts);

      return data;
      }
      }

      and is accessed from a class within a servlet
      try {
      UserBeanPK pk = new UserBeanPK(
      data.getStringAttribute("client"),
      data.getStringAttribute("userid")
      );
      User bean = ((UserHome) de.xifs.helper.ReferenceHolder.getReference("User")).findByPrimaryKey(pk);
      bean.setUserData(data);
      }
      catch(Exception e) {
      throw new Exception("Failed to edit User by primary key"+e.toString());
      }
      Any hints.
      Greetings Dan