1 Reply Latest reply on Sep 29, 2004 9:58 AM by pique niquer

    CMP Bean seems to change its id in cache?

    gumreal Newbie

      Hi
      I badly need your help!
      Using jboss3.2.3 and mysql, I create a cmp bean called userEJB. The problem is:
      when I create a new bean, jboss cache this bean in an existed bean instance, then this new bean using an old id will be store into my db; on the other hand, jboss insert a new user with new id but old user information into my db.
      my code goes here:
      Remote:

      public interface User extends EJBObject {
       public UserDetails getDetails() throws RemoteException;
       public void setDetails(UserDetails userDetails) throws RemoteException;
       }
      

      Home:
      public interface UserHome extends EJBHome {
      
       public User create(UserDetails userDetails)
       throws RemoteException,CreateException;
      
       public User findByPrimaryKey(Integer pk)
       throws FinderException, RemoteException;
      
       public Collection findByNameAndPwd(String userName,String pwd)
       throws FinderException, RemoteException;
      
       public Collection findAll()
       throws FinderException, RemoteException;
      
       public Collection findByUserName(String userName)
       throws FinderException, RemoteException;
      }

      Bean:
      public abstract class UserEJB implements EntityBean{
       private EntityContext context;
       private UserDetails userDetails;
      
       public Integer ejbCreate(UserDetails userDetails) throws CreateException{
       setUserID(userDetails.getUserID());
       setDetails(userDetails);
       return null;
       }
      
       public void ejbPostCreate(UserDetails userDetails){}
      
       public UserDetails getDetails() {
       userDetails = new UserDetails();
       userDetails.setUserID(getUserID());
       userDetails.setUserName(getUserName());
       userDetails.setPassword(getPassword());
       userDetails.setDate(getDate());
       return userDetails;
       }
      
       public void setDetails(UserDetails userDetails) {
       setUserName(userDetails.getUserName());
       setPassword(userDetails.getPassword());
       setDate(userDetails.getDate());
       }
      
       public void setEntityContext(EntityContext ctx){
       context = ctx;
       }
       public void unsetEntityContext(){
       context = null;
       }
      
       public void ejbActivate(){userDetails = null; }
       public void ejbPassivate(){userDetails = null; }
       public void ejbLoad() {}
       public void ejbStore() {}
       public void ejbRemove() { }
      
       public abstract java.sql.Date getDate();
       public abstract String getPassword();
       public abstract Integer getUserID();
       public abstract String getUserName();
      
       public abstract void setDate(java.sql.Date date);
       public abstract void setPassword(String string);
       public abstract void setUserID(Integer integer);
       public abstract void setUserName(String string);
      }

      ejb-jar.xml:
      <entity>
       <ejb-name>UserEJB</ejb-name>
       <home>spitoolkit.core.server.UserHome</home>
       <remote>spitoolkit.core.server.User</remote>
       <ejb-class>spitoolkit.core.server.UserEJB</ejb-class>
       <persistence-type>Container</persistence-type>
       <prim-key-class>java.lang.Integer</prim-key-class>
       <reentrant>false</reentrant>
       <cmp-version>2.x</cmp-version>
       <abstract-schema-name>User</abstract-schema-name>
      
       <cmp-field><field-name>userID</field-name></cmp-field>
       <cmp-field><field-name>userName</field-name></cmp-field>
       <cmp-field><field-name>password</field-name></cmp-field>
       <cmp-field><field-name>date</field-name></cmp-field>
       <primkey-field>userID</primkey-field>
       <query>
       <query-method>
       <method-name>findByNameAndPwd</method-name>
       <method-params>
       <method-param>java.lang.String</method-param>
       <method-param>java.lang.String</method-param>
       </method-params>
       </query-method>
       <ejb-ql>
       SELECT OBJECT(o) FROM User o
       WHERE o.userName = ?1 AND o.password = ?2
       </ejb-ql>
       </query>
       <query>
       <query-method>
       <method-name>findAll</method-name>
       <method-params/>
       </query-method>
       <ejb-ql>
       SELECT OBJECT(o) FROM User o
       </ejb-ql>
       </query>
       <query>
       <query-method>
       <method-name>findByUserName</method-name>
       <method-params>
       <method-param>java.lang.String</method-param>
       </method-params>
       </query-method>
       <ejb-ql>
       SELECT OBJECT(o) FROM User o
       WHERE o.userName = ?1
       </ejb-ql>
       </query>
      </entity>
      

      jbosscmp-jdbc.xml
      <entity>
       <ejb-name>UserEJB</ejb-name>
       <table-name>core_user</table-name>
       <cmp-field>
       <field-name>userID</field-name>
       <column-name>userID</column-name>
       </cmp-field>
       <cmp-field>
       <field-name>userName</field-name>
       <column-name>userName</column-name>
       <jdbc-type>VARCHAR</jdbc-type>
       <sql-type>VARCHAR(100)</sql-type>
       </cmp-field>
       <cmp-field>
       <field-name>password</field-name>
       <column-name>password</column-name>
       <jdbc-type>VARCHAR</jdbc-type>
       <sql-type>VARCHAR(100)</sql-type>
       </cmp-field>
       <cmp-field>
       <field-name>date</field-name>
       <column-name>date</column-name>
       <jdbc-type>DATE</jdbc-type>
       <sql-type>DATE</sql-type> </cmp-field>
       </entity>
      


      what's wrong with it? thanks for any help!
      util:
      public class UserDetails implements Serializable
      {
       private Integer userID;
       private String userName;
       private String password;
       private Date date;
      
       public UserDetails() {
       this(new Integer(0),"","",new Date(0));
       }
       public UserDetails(Integer userID, String userName, String password, Date date) {
       this.userID = userID;
       this.userName = userName;
       this.password = password;
       this.date = date;
       }
      
       public String toString(){return userName; }
      
       public Integer getUserID() { return userID; }
       public void setUserID(Integer userID) { this.userID = userID; }
      
       public String getUserName() {return userName;}
       public void setUserName(String userName){
       this.userName = userName;
       }
      
       public String getPassword() {return password;}
       public void setPassword(String password) {
       this.password = password;
       }
      
       public Date getDate() { return date;}
       public void setDate(Date date){this.date = date;}
      }