RE: [JBoss-user] Primary Key warnings

2001-05-18 Thread Norton Lam

I changed my hashCode() method as recommended below.  I also
made the default constructor change as recommended in the
posts referenced by Alexander (sorry I forgot to check the
archives first).

However, I'm still getting the same warnings.

Any other suggestions?

Thanx.

Norton

-Original Message-
From: danch (Dan Christopherson) [mailto:[EMAIL PROTECTED]]
Sent: Thursday, May 17, 2001 5:14 PM
To: [EMAIL PROTECTED]
Subject: Re: [JBoss-user] Primary Key warnings


 
   /**
* Hash code method.
*/
   public int hashCode() {
 return(super.hashCode());
   }


This is the problem. This is delegating to the Object.hashCode method 
that uses the object's address as its input, so when the verifier tries 
to verify that your hashCode method is right (by creating two keys and 
comparing the hashes) it gets different answers when it should get the 
same answer.

maybe
return _guid.toString().hashCode()

?

-danch



___
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user

___
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user



RE: [JBoss-user] Primary Key warnings

2001-05-18 Thread Rafael Alves Chaves

Norton,

Your PK equals method:

public boolean equals(Object obj) {
GUID compareTo = (GUID)obj;

if (_guid.toString().equals(compareTo.toString())) {
  return(true);
}

return(false);
  }

The correct would be:
...
if (_guid.toString().equals(compareTo._guid.toString())) {
...

 Correct?

Rafael

On Fri, 18 May 2001, Norton Lam wrote:

 I changed my hashCode() method as recommended below.  I also
 made the default constructor change as recommended in the
 posts referenced by Alexander (sorry I forgot to check the
 archives first).
 
 However, I'm still getting the same warnings.
 
 Any other suggestions?
 
 Thanx.
 
 Norton
 
 -Original Message-
 From: danch (Dan Christopherson) [mailto:[EMAIL PROTECTED]]
 Sent: Thursday, May 17, 2001 5:14 PM
 To: [EMAIL PROTECTED]
 Subject: Re: [JBoss-user] Primary Key warnings
 
 
  
/**
 * Hash code method.
 */
public int hashCode() {
  return(super.hashCode());
}
 
 
 This is the problem. This is delegating to the Object.hashCode method 
 that uses the object's address as its input, so when the verifier tries 
 to verify that your hashCode method is right (by creating two keys and 
 comparing the hashes) it gets different answers when it should get the 
 same answer.
 
 maybe
   return _guid.toString().hashCode()
 
 ?
 
 -danch
 
 
 
 ___
 JBoss-user mailing list
 [EMAIL PROTECTED]
 http://lists.sourceforge.net/lists/listinfo/jboss-user
 
 ___
 JBoss-user mailing list
 [EMAIL PROTECTED]
 http://lists.sourceforge.net/lists/listinfo/jboss-user
 


___
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user



RE: [JBoss-user] Primary Key warnings

2001-05-18 Thread Rafael Alves Chaves

 No...
 
 The _guid property is private.  I've overridden the
 toString() method to return a _guid.toString().

  Ok, but an instance of a class have full access to private fields of
another instances of the same class.

  Norton, could you show us the complete code for GUID class?

Bye,

Rafael



___
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user



RE: [JBoss-user] Primary Key warnings

2001-05-18 Thread Norton Lam

Ah... I understand now. 

The problem is that my GUID class, by definition, creates 
a new GUID for every call to the default constructor.  I 
use it to create unique IDs for newly created EJBs. 
Therefore, the below code could never be true.  Given 
that, I guess I'll just have to live with the warnings. 

I'm assuming I'm not violating the EJB spec by designing 
my PK class like this, am I?  I'll have to check into that. 

I was thinking that you guys (the JBoss developers) were 
checking for equals() and hashCode() this way due to 
the spec, but I guess there's no other way for you to 
check for the override of these methods generically. 

Thanx to everyone that tried to help. 

Norton 

P.S.  Dain, I'm using BMP for the moment...

-Original Message-
From: Dain Sundstrom
To: '[EMAIL PROTECTED]'
Sent: 5/18/01 1:44 PM
Subject: RE: [JBoss-user] Primary Key warnings

Norton,

I had this same problem. The code you are running into follows:

Object one, two;
try {
one = cls.newInstance();
two = cls.newInstance();
try {
if(!one.equals(two)) {
status = false;
fireSpecViolationEvent(entity, new
Section(9.2.9.b));
}
} catch(NullPointerException e) {} // That's OK - the
implementor
expected the fields to have values

try {
if(one.hashCode() != two.hashCode()) {
status = false;
fireSpecViolationEvent(entity, new
Section(9.2.9.c));
}
} catch(NullPointerException e) {} // That's OK - the
implementor
expected the fields to have values
} catch(IllegalAccessException e) {
// other stuff..   

As you see your pk class needs to either throw a NullPointerException or
return a hash codes that are equal.  This is kind of lame, so I just
have my
PK just throws a NullPointerException when equals or hashCode is called
on
an uninitialized instance.

By the way, I think the _guid field must be public for CMP to work.

-dain


___
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user



[JBoss-user] Primary Key warnings

2001-05-17 Thread Norton Lam

Hi,

I'm getting warnings from the JBoss verifier that I need to override
equals()
and hashCode() in my primary key class.  The problem is, I *am* overriding
these methods.

At the risk of world-wide embarrassment, here's the log and code snippets:

[Verifier] 
Bean   : Item
Section: 9.2.9
Warning: The primary key class must override equals().

[Verifier] 
Bean   : Item
Section: 9.2.9
Warning: The primary key class must override hashCode().


/**
 * Class that provides a Global Unique ID (GUID)
 * for primary keys in the database.
 */
public class GUID implements Serializable {
 .
 .
 .

  /**
   * Test for equality.
   */
  public boolean equals(Object obj) {
GUID compareTo = (GUID)obj;

if (_guid.toString().equals(compareTo.toString())) {
  return(true);
}

return(false);
  }

  /**
   * Hash code method.
   */
  public int hashCode() {
return(super.hashCode());
  }
.
.
.
}

The method signatures are correct, right?  What
am I missing?

Thanx.

Norton

___
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user



Re: [JBoss-user] Primary Key warnings

2001-05-17 Thread danch (Dan Christopherson)

 
   /**
* Hash code method.
*/
   public int hashCode() {
 return(super.hashCode());
   }


This is the problem. This is delegating to the Object.hashCode method 
that uses the object's address as its input, so when the verifier tries 
to verify that your hashCode method is right (by creating two keys and 
comparing the hashes) it gets different answers when it should get the 
same answer.

maybe
return _guid.toString().hashCode()

?

-danch



___
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user