-
Notifications
You must be signed in to change notification settings - Fork 7
Description
While testing some database persistence, I've found that what I write out to the datastore and what gets read back from it is not always in the same format.
Example: write out price as a BigDecimal("0"), but when read back in I get BigDecimal("0.00"). Or writing out a java.util.Date, and the persistence layer reads it in as a java.sql.Timestamp.
Though the values they represent are effectively equivalent, BigDecimal.equals() returns false if the values have different scales. Timestamp.equals(Date) will always return false, but Date.equals(Timestamp) will return true if the represented time is the same.
Can we get a feature to control how property values are compared for equality?
Proposal: introduce a new property to @Property annotation:
@interface Property {
...
PropertyEquivalence equivalenceMethod default PropertyEquivalence.EQUALS;
}
enum PropertyEquivalence { EQUALS, COMPARE_TO; }
When equivalence method is COMPARE_TO, then the Pojomator should sanity check that 1) the property policy does not include hash coding, and 2) the property type is Comparable,
In the meantime, I will keep calling BigDecimal.setScale, and converting Dates to Timestamps in setters. :(