LaLiLuna thank you kindly for getting back to me on such short notice.
I've recreated the test environment from scratch and retested my findings, ending with the same conclusion.
As long as i have a composite foreign key pointing to a composite primary key, the primary key's columns cannot contain "_"(underscore) or else I get a :
Quote:
org.hibernate.MappingException: Unable to find column with logical name: PC1_ID in org.hibernate.mapping.Table(DD.PKTBL_T) and its related supertables and secondary tables
Please see the code below.
SQL DDL for the two tables :
Code:
create table PKTBL_T (
PC1_ID INTEGER not null,
PC2_ID INTEGER not null,
DESCR VARCHAR2(256 BYTE)
);
alter table PKTBL_T add constraint PK_PKTBL_T primary key (PC1_ID, PC2_ID);
alter table PKTBL_T add constraint AK_ID_AK_PKTBL_T unique (PC1_ID);
create table FKTBL_T (
ID INTEGER not null,
FC1_ID INTEGER,
FC2_ID INTEGER,
MSG VARCHAR2(256 BYTE)
);
alter table FKTBL_T add constraint PK_FKTBL_T primary key (ID);
alter table FKTBL_T add constraint LG_LGLVL_FK foreign key (FC1_ID, FC2_ID)
references PKTBL_T (PC1_ID, PC2_ID);
Annotated Java classes.
Class for PKTBL_T ("primary key" table, towards which the foreign key points):
Code:
@Entity
@IdClass(PktblTEntityPK.class)
@Table(schema = "DD", name = "PKTBL_T")
public class PktblTEntity
{
private BigInteger pc1Id;
private BigInteger pc2Id;
private String descr;
@Id
@Column(name = "PC1_ID", nullable = false, length = 22)
public BigInteger getPc1Id() {...}
public void setPc1Id(BigInteger pc1Id) {...}
@Id
@Column(name = "PC2_ID", nullable = false, length = 22)
public BigInteger getPc2Id() {...}
public void setPc2Id(BigInteger pc2Id) {...}
@Basic
@Column(name = "DESCR", length = 256)
public String getDescr() {...}
public void setDescr(String descr) {...}
}
public class PktblTEntityPK implements Serializable
{
private java.math.BigInteger pc1Id;
private java.math.BigInteger pc2Id;
/* hashCode,equals and getters/setters for pc1Id/pc2Id */
}
Class for FKTBL_T ("foreign key" table, containing the foreign key that points toward PKTBL_T):
Code:
@Entity
@Table(schema = "DD", name = "FKTBL_T")
public class FktblTEntity
{
private BigInteger id;
private String msg;
private PktblTEntity fkEnt;
@Id
@Column(name = "ID", nullable = false, length = 22)
public BigInteger getId() {...}
public void setId(BigInteger id) {...}
@Basic
@Column(name = "MSG", length = 256)
public String getMsg() {...}
public void setMsg(String msg) {...}
@OneToOne
@JoinColumns({@JoinColumn(name = "FC1_ID", referencedColumnName = "PC1_ID"), @JoinColumn(name = "FC2_ID", referencedColumnName = "PC2_ID")})
public PktblTEntity getFkEnt() {...}
public void setFkEnt(PktblTEntity fkEnt) {...}
}
Please let me know if you need more detail. I'm trying to keep it as short as possible.
Thank you again for all your time and precious advices. Your effort is highly appreciated,
Richard