I have a question about the way Middlegen-Hibernate has interpreted some foreign keys in my database schema. As can be seen below, the mapping generated for TIA00573 has both a "key-many-to-one" and a "one-to-one" mapping generated against TIA00571.
The database is such that the two tables are based on the same primary key but there will not always be rows present in TIA0573. For a row in TIA00573, there will always be a row in TIA00571, hence the constrained="true" setting in the TIA00573 mapping.
I understand from the DDL why Middlegen has generated a key-many-to-one, but I'm not sure it is actually correct as it is really a zero or one relationship. When I run a "from Tia00571" query, Hibernate throws an IllegalArgumentException for reasons I have yet to fathom out.
Any thoughts on this would be gratefully received.
Best Regards
Chris
Code:
-- DDL Statements for foreign keys on Table "CLEX "."TIA00571"
ALTER TABLE "CLEX "."TIA00571"
ADD CONSTRAINT "FK01" FOREIGN KEY
("CNTR_ID")
REFERENCES "COMMON "."TIA00569"
("CNTR_ID")
ON DELETE RESTRICT
ON UPDATE NO ACTION;
ALTER TABLE "CLEX "."TIA00571"
ADD CONSTRAINT "FK02" FOREIGN KEY
("CLAIM_CASE_NUMBER")
REFERENCES "CLEX "."TIA00570"
("CLAIM_CASE_NUMBER")
ON DELETE RESTRICT
ON UPDATE NO ACTION;
-- DDL Statements for foreign keys on Table "CLEX "."TIA00573"
ALTER TABLE "CLEX "."TIA00573"
ADD CONSTRAINT "FK01" FOREIGN KEY
("CLAIM_CASE_NUMBER" ,
"CNTR_ID" )
REFERENCES "CLEX "."TIA00571"
("CLAIM_CASE_NUMBER" ,
"CNTR_ID" )
ON DELETE RESTRICT
ON UPDATE NO ACTION;
Middlegen generated mappings based on the above for TIA00571 and TIA00573...
Code:
<class name="Tia00571" table="TIA00571" schema="CLEX" proxy="Tia00571">
<composite-id name="comp_id" class="Tia00571PK">
<!-- bi-directional many-to-one association to Tia00570 -->
<key-many-to-one name="tia00570" class="Tia00570">
<column name="CLAIM_CASE_NUMBER" />
</key-many-to-one>
<!-- bi-directional many-to-one association to Tia00569 -->
<key-many-to-one name="tia00569" class="Tia00569">
<column name="CNTR_ID" />
</key-many-to-one>
</composite-id>
<property name="titleType" type="java.lang.String" column="TITLE_TYPE" length="1"/>
<!-- etc... -->
<!-- associations -->
<!-- bi-directional one-to-one association to Tia00573 -->
<one-to-one name="tia00573" class="Tia00573" outer-join="auto"/>
</class>
</hibernate-mapping>
<class name="Tia00573" table="TIA00573" schema="CLEX" proxy="Tia00573">
<composite-id name="comp_id" class="Tia00573PK">
<!-- bi-directional one-to-one association to Tia00571 -->
<key-many-to-one name="tia00571" class="Tia00571">
<column name="CLAIM_CASE_NUMBER" />
<column name="CNTR_ID" />
</key-many-to-one>
</composite-id>
<property name="leadContractId" type="java.lang.String" column="LEAD_CONTRACT_ID" not-null="true" length="10"/>
<!-- etc... -->
<!-- associations -->
<!-- bi-directional one-to-one association to Tia00571 -->
<one-to-one name="tia00571" class="Tia00571" outer-join="auto" constrained="true"/>
</class>
</hibernate-mapping>