I have been migrating from hibernate 4 to hibernate 5. It is ok in hibernate 4, but doesn't work in hibernate 5.
I am getting exception:
Caused by: org.hibernate.MappingException: Foreign key (FKf6eo63yo42ylh7vl5klap2eum:ProductParent [parent_id])) must have same number of columns as the referenced primary key (ProductParent [parent_id,product_id])
This is my hibernate mapping:
@Entity public class ProductParent implements Serializable {
@Id
@OneToOne()
@JoinColumn(name = "product_id")
private AbstractProduct product = new AbstractProduct();
@ManyToMany(cascade = ALL, fetch = EAGER)
@JoinTable(name = PRODUCTPARENT, joinColumns = { @JoinColumn(name = "product_id") }, inverseJoinColumns = { @JoinColumn(name = "parent_id") })
private Set<ProductParent> parents = new HashSet<>();
and table structure:
CREATE TABLE productparent (
product_id bigint NOT NULL,
parent_id bigint,
CONSTRAINT fk_parent_id FOREIGN KEY (parent_id) REFERENCES abstractproduct (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fk_product_id FOREIGN KEY (product_id) REFERENCES abstractproduct (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT product_id_parent_id_should_be_unique UNIQUE (product_id, parent_id)
)
Could you help me that?