Senior |
|
Joined: Fri May 14, 2004 9:37 am Posts: 122 Location: Cologne, Germany
|
Hi there,
perhaps this is another Bug in HibernateTools 3.0 Alpha4.
If the hashCode() Method is generate it will not ensure that a mandantory field isn't null. So the following scenario will lead to a NPE:
A User creates a new Object by opening a dialog so the default Constructor will be used.
No Mandantory field is set so far if I now call the hashCode Method that will cause a NPE.
The code that will do the trick looks like:
buf.append(result)
.append(" = 37 * ")
.append(result)
.append(" + ")
// if ( property.isOptional() ) {
.append("( ")
.append( getGetterSignature(property) )
.append("() == null ? 0 : ")
// }
.append(cast)
.append(thisName)
.append(".")
.append( getGetterSignature(property) )
.append("()")
.append(hashCode)
// if ( property.isOptional() )
.append(" )");
}
return buf.toString();
Hmm might I get Points for finding bugs ? ;)
_________________ regards
Olaf
vote if it helped
|
|