• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Over Writing the equals method

 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay I have tried to solved this issue but I am not successful. What I have done is over write the equals method in a domain object. The comparison fails when the two objects are compared in this segment of code:



I have proven the *obj* is not null. I have proven the objects are in fact the same class by printing out the class info. I have verified the hashcode for the objects are the same I have verified the classloaders are the same for the two objects.

I just don't see why the statement fails to evaluate true.

Any suggestions would be welcome now..........
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you confirmed that the code you posted there is actually being run? And that is actually comparing the objects you think it's comparing? And that it returns true in the else-clause that you didn't post?
 
Russell Ray
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your reply.

I have confirmed the process is falling into the if clause and the print statement is being printed out...... This means false is returned from the equals method and no other action is taking place inside the equals method.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then to me, it looks like the code is doing what it's supposed to be doing. Do you still have a problem with it?
 
Russell Ray
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem was a Hibernate Proxy object was being passed in and that's what caused the equals method to fail. Once I force the proxy object to be populated with the implementation data.......all worked as designed.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought there must be more to it than your original post, but I would never have guessed that would be the problem. Anyway, onwards to the next challenge!
 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the object is not null, then it means that either
1. Classes are loaded from different class-loaders
2. They are different classes, different on inheritance hierarchy.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic