| Article: |
Don't Let Hibernate Steal Your Identity | |
| Subject: | Version usage | |
| Date: | 2006-11-09 02:12:01 | |
| From: | jbc4 | |
| Should the version of the object not feature in the equals() and hashcode() methods? | ||
Showing messages 1 through 1 of 1.
-
Version usage
2006-11-09 19:44:11 jbrundege [View]



The suggested definition of equals() is that if two objects represent the same row in the database, they should be equal. For that we just need the id (which is the database primary key). They may not have identical data, but if you save one its data will go in the database. If you try to save the other one you will get a ConcurrentModificationException (that's what the version does), which is appropriate to keep two people from stepping on each other's data. Hence to Java the objects are equal because they are two representations of the same database row, but Hibernate will know not to allow one such object to overwrite another one.
James