JPA Composite key with ManyToOne getting org.hibernate.PropertyAccessException: could not set a field value by reflection setter of

前端 未结 2 2029
伪装坚强ぢ
伪装坚强ぢ 2020-12-18 22:15

I have a composite key ContractServiceLocationPK made out of three id\'s (contractId, locationId, serviceId) of type long

2条回答
  •  感动是毒
    2020-12-18 22:42

    You need to put the getters and setters in your @Embeddable class as well, your hashCode() and equals() methods will go in to that class which I couldn't see in your class posted here.

    In order to save the ContractServiceLocation, following objects needs to be saved first because you are using their ids as composite key for the ContractServiceLocation, right? Here what you are doing is you are creating these as new objects so obviously they won't have their id, because they are not persisted. so you need to persist them first and use the persisted objects and set objects into the ContractServiceLocation.

        Service service = new Service();
        // Set all service properties       
        Contract contract = new Contract();
        // Set all contract properties
        Location location = new Location();
        // Set all location properties
    

提交回复
热议问题