0 Replies Latest reply on Jun 15, 2005 10:07 AM by infantpapa

    Help:: Problem with Custom Primary Key class in CMP

    infantpapa

      This is what iam getting on my console

      :18:37:52,743 ERROR [BeanLock] removing bean lock and it has tx set! org.jboss.ej
      b.plugins.lock.QueuedPessimisticEJBLock@32dfd4, bean=User, id=com.webforum.entit
      y.user.UserEntityPK@6, refs=0, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId
      =Nagadev/33, BranchQual=, localId=33], synched=null, timeout=5000, queue=[]
      18:37:52,753 ERROR [LogInterceptor] RuntimeException in method: public abstract
      java.lang.Integer com.webforum.entity.user.UserEntity.getUserId()
      throws java.rm
      i.RemoteException:
      java.lang.IllegalStateException: removing bean lock and it has tx set!
      at org.jboss.ejb.plugins.lock.QueuedPessimisticEJBLock.removeRef(QueuedP
      essimisticEJBLock.java:461)





      and i got some info that this can occur when primary key class hashcode/equals methods implemented badly

      Please verify my PK class


      here it is

      package com.webforum.entity.user;

      import java.io.Serializable;

      public class UserEntityPK implements Serializable {

      public Integer userId; //primary-key field

      public UserEntityPK() {
      }

      public UserEntityPK(Integer userId) {
      this.userId = userId;
      }

      public Integer getUserId() {
      return userId;
      }

      /**
      * This is the overridden method of Object class
      * @param obj reference object to compare
      * @return boolean trueif this object is same as the object
      * argument, false otherwise.
      */
      public boolean equals(Object obj) {
      if (obj == null || !(obj instanceof UserEntityPK))
      return false;
      else if (((UserEntityPK)obj).userId == userId)
      return true;
      else
      return false;

      }

      public String toString(){
      return String.valueOf(userId);
      }

      /**
      * This is the overriden method which returns hashCode
      * @return int the hashCode
      */
      public int hashCode() {
      return userId.hashCode();
      }
      }













      This is code snippet where iam using Bean method () getUserId()



      Collection colUser=null;
      try{

      ctx=new InitialContext();
      userHome =(UserEntityHome)ctx.lookup("User");

      UserEntityPK userPK=new UserEntityPK(userId);

      UserEntity userEntity=userHome.findByPrimaryKey(userPK);

      User user=new User();
      user.userId=userEntity.getUserId();------where iam getting the problem



      Please help in this.