Pages

Friday, June 11, 2010

Entity comparison

Today I was doing comparison between two JPA entities. I just accessed the the values via getter setters and checking the equality of them. On the debugger I am getting the values equal but the my comparison is returning me false. I was stuck a bit. Then the point became clear. It was a really silly mistake. The member variables in the entity are the wrapper class of the primitive types  of JAVA. So direct equality check will compare the whole objects rather than the values. In this case obviously two objects are not same. So to compare first we need to have the primitive values using doubleValue() or intValue() function. Or the wrapper class's compare() function can be used.

No comments:

Post a Comment