-->
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.  [ 2 posts ] 
Author Message
 Post subject: foreign key constraint
PostPosted: Wed Mar 23, 2005 4:37 am 
Newbie

Joined: Wed Mar 23, 2005 4:29 am
Posts: 7
Hi,

I got a real basic question. I'm working with Hibernate 2 and a mcKoi database.
I have two classes (A and B). Class A has an attribute (say: b1) that is an objec of class B. Now in my mapping I wrote:
<many-to-one name="b1" class="B" column="b1"/>

The problem I have is when I want to save an object of Class A. McKoi gives a foreign key constraint exception, saying that their isn't a primary key of B that matches the foreign key in A.

I can solve this by saving B first in my code, but I was wondering if there's a way to do this in the mapping. So that Hibernate does that automatically.

Thanks in advance!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 23, 2005 4:50 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
Make the relationship nullable:
Code:
        <many-to-one
            name="b1"
            class="B"
            foreign-key="b1_fk1"
            column="b1"
            not-null="false"
        />


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

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.