-->
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.  [ 4 posts ] 
Author Message
 Post subject: Unable to make my many-to-one foreign key null
PostPosted: Mon Apr 18, 2011 7:50 am 
Newbie

Joined: Mon Apr 18, 2011 7:45 am
Posts: 2
Hi,

I am using a many-to-one relationship to model a linked list in my database. See subjoined code snippet.

Code:
public class Instruction
{
    ...
    [ManyToOne(Column = "NextInstructionId")]
    public virtual Instruction Next { get; set; }
    ....
}


Now, create a linked list of instruction works fine. The last instruction get a NULL value in the NextInstructionId column. But, when I remove the last instruction from my list, then the previous one becomes last. So, I set the Next property to null. But, on update, the database engine complains that the foreign key constraint is not met, because NextInstructionId is null.

Does anyone know what might happen here?

Thanks,
Alexander.


Top
 Profile  
 
 Post subject: Re: Unable to make my many-to-one foreign key null
PostPosted: Mon Apr 18, 2011 11:19 am 
Newbie

Joined: Mon Apr 18, 2011 10:51 am
Posts: 2
Well you can not insert null into a ForeignKey column with a constraint that awaits a valid ForeignKey.


Top
 Profile  
 
 Post subject: Re: Unable to make my many-to-one foreign key null
PostPosted: Tue Apr 19, 2011 1:44 am 
Newbie

Joined: Mon Apr 18, 2011 7:45 am
Posts: 2
tkn wrote:
Well you can not insert null into a ForeignKey column with a constraint that awaits a valid ForeignKey.


Sure, but it is possible to have a nullable foreign key field. Even more, when initially inserting a null value in the foreign key field, the database finds it ok. So, why does an update from a valid value to a null value does not work?


Top
 Profile  
 
 Post subject: Re: Unable to make my many-to-one foreign key null
PostPosted: Tue Apr 19, 2011 3:17 am 
Beginner
Beginner

Joined: Mon Apr 04, 2011 3:31 am
Posts: 41
hi

Check this Two Link Related to your problem

Link 1

Link 2

_________________
Thanks
Niki


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.