Hello, i have this two tables in PostgreSQL:
Code:
CREATE TABLE COLLEGIO (
codColl NUMERIC(4,0) NOT NULL,
provincia VARCHAR(35) NOT NULL,
/* Other fileds */
PRIMARY KEY (codColl, provincia)
);
CREATE TABLE ELETTORE (
codEl VARCHAR(16) NOT NULL,
/* Other fileds */
PRIMARY KEY (codEl),
FOREIGN KEY (codColl, provincia) REFERENCES COLLEGIO (codColl, provincia)
);
I have created the classes with these XML files:
Code:
<class name="Collegio" table="COLLEGIO">
<composite-id name="collegioKey" class="entities.keys.CollegioKey">
<key-property type="int" name="codColl"/>
<key-property type="string" name="provincia"/>
</composite-id>
<set name="elettori" table="ELETTORE" inverse="true" lazy="true" fetch="select">
<key column="codel" not-null="true"/>
<one-to-many class="entities.Elettore" />
</set>
</class>
<class name="Elettore" table="ELETTORE">
<id name="codEl" column="codEl">
<generator class="assigned" />
</id>
<many-to-one name="collegio" class="entities.Collegio" fetch="select">
<column name="codcoll" not-null="true"/>
<column name="provincia" not-null="true"/>
</many-to-one>
</class>
But when i try to run the project (for example for listing the content of the table "COLLEGIO") hibrenate give me this error:
Code:
org.hibernate.MappingException: Foreign key (FK_da1lkg53is2jg7wmcddlarf6s:ELETTORE [codel])) must have same number of columns as the referenced primary key (COLLEGIO [codColl,provincia])
What I have done wrong?