2 Replies Latest reply on Jul 24, 2002 12:52 PM by zommick

    BUG: FindByPrimaryKey fails to find object when using compou

    zommick

      I'm using JBoss 3.0 production release with CMP. I'm using a compound key. I can use a findAll which returns a collection of my beans; however, when I do a findByPrimaryKey(myKeyPK), it says the object is not found even though it is found in the findAll method.

        • 1. Re: BUG: FindByPrimaryKey fails to find object when using co
          tbfmicke

          One explanation might be that you have forgotten to write the equals and hashcode methods in your primary key class. (Or have a but in them somewhere).

          Regards

          • 2. Re: BUG: FindByPrimaryKey fails to find object when using co
            zommick

            As you can see, the hashcode and equals appear to be fine.

            public class RequestPK implements java.io.Serializable {

            public Integer requestId;
            public Integer recordingId;

            public Integer getRequestId() {
            return requestId;
            }

            public Integer getRecordingId() {
            return recordingId;
            }

            public boolean equals(Object obj) {

            if (obj == null || !(obj instanceof RequestPK)) {
            return false;
            }

            RequestPK other = (RequestPK)obj;
            if ( this.requestId.intValue() == other.requestId.intValue()
            && this.recordingId.intValue() == other.recordingId.intValue() ) {
            return true;
            }
            else {
            return false;
            }
            }

            public int hashCode() {
            return (requestId.intValue() + " " + recordingId.intValue()).hashCode();
            }

            public String toString() {
            return requestId.intValue() + " " + recordingId.intValue();
            }

            public RequestPK() {}

            public RequestPK( Integer requestId, Integer recordingId ) {
            this.requestId = requestId;
            this.recordingId = recordingId;
            }
            }