I have a POJO class that already has equals and hashcode defined and used for many legacy objects that are saved to a DB so changing how that object works is not an option.
Her's a simplified code:
@EqualsAndHashCode(of = {"id"}, callSuper = false)
public class BenefitContract {
private static final Logger LOGGER = LoggerFactory.getLogger(BenefitContract.class);
@Id
@GeneratedValue(generator = "ss_benefit_contract_sequence", strategy = GenerationType.SEQUENCE)
@Column(name = "SS_BENEFIT_CONTRACT_ID")
private Long id;
private UUID guid;
private Benefit benefit;
private LocalDate startDate;
private BigDecimal contractCost;
...
private static Set<BenefitContract> uniqueContracts;
...
}
So, I want to add benefit contracts to the uniqueContracts based on employee, startDate and contractCost so as to eliminate duplicate contracts for the same employee based on these fields.
How that could be done given I can't re-define equals and hashcode?