Hello. I'm trying to save a new object to my many to many table.
Error:
Could not set field value [8652] value by reflection : [class core.billing.data.entity.repair.RepairContractKey.contractId] setter of core.billing.data.entity.repair.RepairContractKey.contractId;
public class RepairContract {
@EmbeddedId
RepairContractKey id;
@ManyToOne
@JoinColumn(name = "repair_id", referencedColumnName = "id")
@MapsId("repairId")
private Repair repair;
@ManyToOne
@JoinColumn(name = "contract_id", referencedColumnName = "id")
@MapsId("contractId")
private RentalContract contract;
}
public class RepairContractKey implements Serializable {
@Column
Long repairId;
@Column
Long contractId;
}
in service
private void saveRepairContracts(Repair repair) {
final var repairContract = new RepairContract();
repairContract.setContract(rentalContractRepository.findById(value.getId()).orElse(null));
repairContract.setRepair(repair);
// here I get error
repairContractRepository.save(repairContract);
}