I have a composite key ContractServiceLocationPK
made out of three id\'s (contractId
, locationId
, serviceId
) of type long
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
For your original question (not modified variant):
You have to instatiate "ContractServiceLocationPK id" in your ContractServiceLocation class. Replace line:
@EmbeddedId ContractServiceLocationPK id;
with this:
@EmbeddedId ContractServiceLocationPK id = new ContractServiceLocationPK();
Then it should works. Because Hibernate is trying to set properties inside, but fail on NullPointerException.