-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Foreign Key refreing more than one table
PostPosted: Thu Jul 09, 2009 2:22 am 
Newbie

Joined: Wed Jun 03, 2009 2:21 am
Posts: 5
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 ???


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.