Re: BaseDataObject equality
"Robert A. Decker" <[email protected]> Fri, 15 May 2026 15:26:06 +0200
| Newsgroups | gmane.comp.java.cayenne.user |
|---|---|
| Message-ID | <[email protected]> |
yeah, I was feeling a little squeamish overriding equals.... I'll use = your suggestions. Rob > On 15 May 2026, at 15:01, Andrus Adamchik <[email protected]> wrote: >=20 > Technically, ObjectId is the way to check that two objects across = contexts are pointing to the same DB row. Whether this constitutes = equality from a Java perspective or not is a very situational. Sometimes = it is, other times it is not (e.g., when you are comparing property = values).=20 >=20 > So while I don't recall at the moment how (un)safe it is to override = Object.equals(..) from the framework standpoint (probably ok), I usually = avoid doing that for the philosophical reason above :) The alternatives = are either specific comparison methods like "idEquals(..)", using = Map<ObjectId, ?> instead of a Set, etc. >=20 > Andrus >=20 >> On May 15, 2026, at 8:51=E2=80=AFAM, Robert A. Decker = <[email protected]> wrote: >>=20 >> How should I be checking equality between persistent objects, to use = a java.util.HashSet for example? >>=20 >> Is the ObjectId of a BaseDataObject the same across all = ObjectContexts for a database row? >>=20 >> Do people using cayenne override the equals method: >> return this.getObjectId().equals(other.getObjectId()); >>=20 >> Or is there a different way people usually check equality? (compare = primary keys, etc?) >>=20 >> Rob >=20