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.  [ 3 posts ] 
Author Message
 Post subject: [Beginner] Loosen many-to-one constraint
PostPosted: Wed Aug 02, 2006 10:26 am 
Newbie

Joined: Thu Feb 23, 2006 2:00 pm
Posts: 3
Hi,

I have mapped an existing table like following, where a member references an other instance of the same class.

When I load a row where FATHER=0, I get a "no row for the given identifier exists" exception, because '0' is a magic number which mean "no parent" in the database.

I know it's a poor database design but I can't change it... So I would like to set my property to null where no row exists for a given foreign key.

How should I proceed ?

Thanks


Hibernate version: 1.0.2.0

Mapping documents:

<class name="Person" table="PERSON">
<id name="Id" type="Int32" column="ID_PERSON">
<generator class="native" />
</id>
<property name="Name" column="NAME" type="String" length="50" not-null="true" />
<many-to-one name="Father" column="FATHER" class="Person" />
</class>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 02, 2006 10:27 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
This is not currently supported by NHibernate. You may be able to work around it using a view which would map 0 to NULL.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 02, 2006 11:22 am 
Newbie

Joined: Thu Feb 23, 2006 2:00 pm
Posts: 3
sergey wrote:
This is not currently supported by NHibernate. You may be able to work around it using a view which would map 0 to NULL.


Thank you Sergey, I will make pressure on tha dba to use NULL instead of 0... I think it's better for updates.


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