Re: BaseDataObject equality
Andrus Adamchik <[email protected]> Fri, 15 May 2026 09:01:43 -0400
| Newsgroups | gmane.comp.java.cayenne.user |
|---|---|
| Message-ID | <[email protected]> |
--Apple-Mail=_8314E07A-3DB3-4474-8944-28BE51B7C754 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 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 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. Andrus > 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 --Apple-Mail=_8314E07A-3DB3-4474-8944-28BE51B7C754--