Im trying to save List of class instances inside a parent object, with hibernate. Child instance should map to parent by parents ID "CONTRACTID", which is generated.
PARENT:
@Id
@Column(name = "CONTRACTID")
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator = "id_Sequence")
@SequenceGenerator(name = "id_Sequence", sequenceName = "ID_SEQ_CONTRACT")
private Long contract_id;
and then
@OneToMany(targetEntity = CustomerGroup.class, fetch = FetchType.LAZY, cascade = {CascadeType.ALL}, mappedBy = "contractId")
private List<CustomerGroup> customerGroups;
CHILD:
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "CONTRACTID", foreignKey=@ForeignKey(name="CONTRACTID_FK"))
private ContractHolder contractId;
also tried without foreignKey=@ForeignKey(name="CONTRACTID_FK")
I see in database that both fields are existing, parents ID is generated as expected on .save but the FK field of CustomerGroup stays as null when parent is saved.
What am i doing wrong here?
EDIT:
Save code is very simple line in Database.class after setting all the needed values for parent object, also the List of CustomerGroup is set to parent object and saved properly but not the FK autogenerated id
contractRepo.save(contract);
EDIT2:
and if i try to set parent object to @JoinColumn of childeren before saving. like
customerGroup.setContractId(contractHolder);
i get what seems to be an infinite loop. goddamn