EmbeddedId and ManyToOne MappingException


I am getting a org.hibernate.MappingException: Foreign key (FKsduc1t8vj2vaxjnh2855ql81d:ADDRESS [CTRY_ID,STAT_ID])) must have same number of columns as the referenced primary key (STATE_PROV [ID]).

The Address entity has

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "CTRY_ID", referencedColumnName = "CTRY_ID")
@JoinColumn(name = "STAT_ID", referencedColumnName = "STAT_ID")
 private StateProvince stateProvince;

The StateProvince entity has

protected StateProvincePK id;
@JoinColumn(name = "CTRY_ID")
@ManyToOne(optional = false)
private Country country;

StateProvincePK is

public class StateProvincePK implements Serializable
@Size(min = 1, max = 4)
@Column(name = "CTRY_ID")
private String countryId;
@Size(min = 1, max = 4)
@Column(name = "STAT_ID")
private String stateId;

I believe this error is a bug in hibernate, but am unsure, with how it handles an EmbeddedId in a foreign key. I’m using the latest 5.4.2.Final hibernate and JPA 2.2.

I tested this with IdClass as well and it comes up with the same error. Looks like the referencedTable.getPrimaryKey() returns just the ID, might have to do with the foreign key to country on the table as well. Any help is greatly appreciated.