-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: hashCode and serializable
PostPosted: Mon Nov 01, 2004 5:14 pm 
Beginner
Beginner

Joined: Tue Jun 22, 2004 3:16 pm
Posts: 35
I am having problem working on overriding hashCode() method when if reference other objects to get their properties.

Here is the sample:

public int hashCode() {
int result = HashCodeUtil.SEED;
result = HashCodeUtil.hash(result, this.otherOjb1.getName());
result = HashCodeUtil.hash(result, this.otherObj2.getName());

return result;
}

The problem is that when I use EJB and then it breaks. The exception is a "NullPointerException". It seems to me is the otherObj1 is null during the serialization. If I do this and it works fine:

public int hashCode() {
int result = HashCodeUtil.SEED;

if(otherObj1 != null && otherObje2 != null) {
result = HashCodeUtil.hash(result, this.otherOjb1.getName());
result = HashCodeUtil.hash(result, this.otherObj2.getName());
}

else {
result = HashCodeUtil.hash(result, agency);
result = HashCodeUtil.hash(result, broker);
}

return result;
}

Any thoghts?


Thanks,

J


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.