Hear us Roar
Article:
 |
|
Don't Let Hibernate Steal Your Identity
|
| Subject: |
|
Does an #equals() based on a surrogate id help a Set do its job? |
| Date: |
|
2007-04-26 08:45:03 |
| From: |
|
carlos.l.sanchez
|
|
|
|
The arguments in the article make sense, with one exception, which I'll try to illustrate with an example:
Say that a Person has a Set of Claims, and that a Claim's natural id is type+date. Say that I SELECT a Person with his/her Claims, and that one of the Claims has the natural id: typeA+today. Say that I try to add in Java another Claim with the same natural id: if the #equals() is based on the surrogate, not the natural id, I will be able to, but I shouldn't: I used a Set precisely because I want to prevent two Claims with the same natural id before accessing the relational table.
Note that in this case the relational table would have the same natural id with a unique constraint on it, so object and relational models would be consistent.
Thoughts?
|
|
| |