tags:

views:

35

answers:

1

As far as I understand(correct me if I am wrong) Hibernate uses object reference to check the object equality. When Hibernate identifies that there are more than one objects attached to same DB record, it throws following exception.

"a different object with the same identifier value was already associated with the session"

My question is, does Hibernate use equal() method to check the object equality (The default equal method uses object reference)? If it is true, will overridden equal() method change the Hibernate behavior?

Note: My question is not about the issues of implementing equal() or hashCode() methods in a Hibernate persisted object.

Thank you.

+1  A: 

Hibernate uses the entity (i.e. class) and configured id. Over-simplified, this would look somehow like this

o1.getClass().equals(o2.getClass()) && o1.getId().equals(o2.getId())
sfussenegger