#Embedded id can't save

1 messages · Page 1 of 1 (latest)

keen rivet
#

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);
}
mild gladeBOT
#

<@&987246399047479336> please have a look, thanks.

mild gladeBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

mild gladeBOT
#

Closed the thread due to inactivity.

If your question was not resolved yet, feel free to just post a message to reopen it, or create a new thread. But try to improve the quality of your question to make it easier to help you 👍

keen rivet
#

Bump. Anyone?

hollow pier