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: 0, NULL, and referential integrity
PostPosted: Thu Oct 27, 2005 9:33 am 
Newbie

Joined: Thu Oct 27, 2005 9:23 am
Posts: 5
Hello,

given the following mapping:

Code:
<class name="Product, MyObjects" table="Products">
   <id name="Id" column="RecID" type="System.Int64">
      <generator class="native" />
   </id>
   <many-to-one name="Part" class="Part, MyObjects" column="PartID"  />
</class>

<class name="Part, MyObjects" table="Parts">
   <id name="Id" column="RecID" type="System.Int64">
      <generator class="native" />
   </id>
   ...
</class>



We have records, where Products.PartID is 0 and there doesn't exist a record in Parts with Parts.RecID == 0. We all know Products.PartID should be NULL in such cases, but my program is not the only one working on that database...

The problem: when I try to get a record from Products, I get the the following error if Products.PartID does not exist in Parts.RecID:
Quote:
{"No row with the given identifier exists: 0, of class: Part" }



Is there any option to do a outer join and ignore the missing foreign keys? Can I NHibernate something like "treat 0 as NULL"?


Sincerely,
Stefan Lieser


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 27, 2005 10:45 am 
Beginner
Beginner

Joined: Sat Apr 17, 2004 1:11 am
Posts: 36
I had the same question last week or so - legacy schema issues. I ended up creating a view for the table in question that set the column to null if it was equal to 0 and mapped to that view. It worked fine...

benster


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.