tag:blogger.com,1999:blog-11593374.post5858054033661150337..comments2024-03-22T08:46:57.166+00:00Comments on Andrew Beacock's Blog: How to implement a Hibernate-safe equals() method using instanceof and accessors (getters) in EclipseAndrew Beacockhttp://www.blogger.com/profile/01039992884679308726noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-11593374.post-91637181963215242392013-07-10T07:17:01.653+01:002013-07-10T07:17:01.653+01:00if this.id and this.name are null, and other objec...if this.id and this.name are null, and other object has these values. equals should return false, but your implementation returns true, wrong! Have logical boolean condition with all business key fields.<br /><br />In BTW, having id in equals is not a good idea. Always have business key fields (i.e fields which makes object unique)ramrajedotcomhttp://www.ramraje.comnoreply@blogger.comtag:blogger.com,1999:blog-11593374.post-49977183639497053752009-04-10T14:43:00.000+01:002009-04-10T14:43:00.000+01:00You can omit the check for null,because (obj insta...You can omit the check for null,<BR/>because (obj instaceof MyClass) returns false anyway in case obj has value null, no matter its type.<BR/><BR/>Maarten Hogendoorn, JConsultancy.comAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-11593374.post-79392057411128658422009-03-25T09:41:00.000+00:002009-03-25T09:41:00.000+00:00Not sure whether you want to use id as part of you...Not sure whether you want to use id as part of your equals/hashcode (if its generated by hibernate)...in fact thats considered to be a bad practice. Your object should be deoendent on a business keyUnknownhttps://www.blogger.com/profile/08840030274983844360noreply@blogger.comtag:blogger.com,1999:blog-11593374.post-8781093968228445812008-08-18T18:52:00.000+01:002008-08-18T18:52:00.000+01:00Hi, Andrew,What if I don't like hash. I really do...Hi, Andrew,<BR/><BR/>What if I don't like hash. I really don't like the taste. I prefer haggis.<BR/><BR/>Ergo, if I don't like hash do I have to write a hashCode() method?<BR/><BR/>This may be a bit too much personal information: when I ate hash in the past, it used to get stuck in my Nokia phone. Only the receiver portion.<BR/><BR/>(In a way, it was good. I could still talk but didn't have to listen.)<BR/><BR/>Sincerely,<BR/>Nhoj YelrucAnonymousnoreply@blogger.com