dlr-eoc / prosEO

prosEO – A Processing System for Earth Observation Data
GNU General Public License v3.0
14 stars 1 forks source link

Data Model: Review `equals` and `hashCode` methods for persistent objects #162

Closed tangobravo62 closed 1 year ago

tangobravo62 commented 2 years ago

For persistent objects the equals method may not work as expected. Most of the classes (with the notable exception of the recently corrected Product and ProcessingFacility) contain the code:

        if (!super.equals(obj))
            return false;

Probably this should read:

        // Same database object
        if (super.equals(obj))
            return true;

The first variant effectively makes comparing loaded objects and transient objects impossible (because the database IDs differ), and if the IDs match, the subsequent attribute-based check is more or less redundant. Presumably a logic like the general if (this == obj) return true; (as in the second variant) is more appropriate.

Since the code worked up to now, a careful review and test is required before performing a general change of the equals methods.

tangobravo62 commented 2 years ago

Extended to cover hashCode, which needs reviewing, too, for two reasons:

tangobravo62 commented 1 year ago

Fixed with commits 263e292, e28079f, 5776763, aa41d31, all included in prosEO 0.9.3.

Has been run successfully since the deployment of prosEO 0.9.3 in November 2022.