I have the table structure as follows
Table A A_ID primary Key A_col1 A_col2
Table B B_ID Primary Key B_col1 B_col2
Table C C_ID Primary Key C_col1 (FK references either A_ID or B_ID) C_col2
How do we deplict this relationship in Hibermate ?
In by hbm files
A.hbm <one-to-one name="a" class="A" cascade="all" property-ref="aProp" constrained="false"/> B.hbm <one-to-one name="b" class="B" cascade="all" property-ref="bProp" constrained="false"/> C.hbm <many-to-one name="aProp" class="A" column="COL_A" unique="true" insert="false" update="false" /> <many-to-one name="bProp" class="B" column="COL_B" unique="true" not-null="false" />
When i try to save A/B separately, I get an error saying FK constraint violated. Say if i try to save A, attaching C to A, It throws an exception as C expects B, which i dont want. How to acehive this? I gave insert="false" update="false" because, i got an error saying, if i use more than one many-to-one on tha same column, i have to specify one as insert="false" update="false" That is the reason i gave that. My objective is to save A with C set (or) B with C set to it
Can this be acheived somehow?
Can any of you please clarify this ???
|