I have a problem with Hibernate, I want to create a table that is related to another table, but when I generate it, the foreign key is wrong.
Is it possible that Hibernate has a bug?
Here is the code that I use to generate the Foreign Key:
@Id
@JsonProperty("account")
@OneToOne
@JoinColumns({
@JoinColumn(
name = "ACCOUNTCODE_K",
referencedColumnName = "CODE_K"/*, insertable = false, updatable = false*/),
@JoinColumn(
name = "INVOICEDEBTOR_K",
referencedColumnName = "INVOICEDEBTOR_K"/*, insertable = false, updatable = false*/)
})
@javax.validation.constraints.NotNull(message="El campo no puede ser nulo")
private Account account;
And here is the DDL generated in the database:
ALTER TABLE "INVOICES"."ACCOUNTBIEN_T"
ADD CONSTRAINT "FKSWGAGEC55PBL7KIHFE19FWBLO" FOREIGN KEY
("ACCOUNTCODE_K",
"INVOICEDEBTOR_K")
REFERENCES "INVOICES"."ACCOUNT_T"
("INVOICEDEBTOR_K",
"CODE_K")
ON DELETE NO ACTION
ON UPDATE NO ACTION
ENFORCED
ENABLE QUERY OPTIMIZATION ;
You can see that ACCOUNTCODE_K reference INVOICEDEBTOR_K when It would be reference CODE_K and INVOICEDEBTOR_K to the other INVOICEDEBTOR_K.
Thanks for help.