-->
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: Issue with Nullable field
PostPosted: Thu Sep 18, 2008 12:13 pm 
Beginner
Beginner

Joined: Thu Aug 14, 2008 5:31 pm
Posts: 20
Hi,

I have read online:

Quote:
If you want to use NHibernate with .Net 2.0 Nullable Types (int?, DateTime?, etc), all you need to do is to specify full type name of the (non nullable) property.
So, if you've something like "DateTime? DueDate { get; set; }", the mapping will looks something like this: "<propery name='DueDate' type='System.DateTime'/>"
You don't need to do anything else.



Here is my problem now. I have mapped a database table [Cutting], which amongst other fields has got one called 'ClientID'. Now I am trying to load an Entity from another database which have the same [Cutting] table as the one used to configure Nhibernate BUT with the 'ClientID' field missing.

However because it is marked as nullable in my Entity class, it should not cause any harm. But when I call :

Code:
_session.Get<Cutting>(cuttingId);


I get the following exception :

Quote:
could not load an entity. Invalid column name 'ClientID'.



This is how I mapped my ClientID field in the hbm.xml file :

Quote:
<property type="int" name="Clientid" column="[ClientID]" />


What am doing wrong here ?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 18, 2008 12:28 pm 
Beginner
Beginner

Joined: Thu Aug 14, 2008 5:31 pm
Posts: 20
Actually thinking about it... My field is missing so the fact that it's nullable is irrelevant.

Therefore, is there a way of ignoring this field when NHibernate queries the table ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 24, 2008 6:57 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Hmm ... you can try and define a sub-class of Cutting which you use for the main db and the base class for the other db.
Or maybe you can try and use a formula on the ClientId property. The formula then would have to check if the colum ist there and return the value or null if not (don't know if that is possible with SQL).
Or you can define a view on the table in the other db which has a clientid column which contains null.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 24, 2008 7:07 am 
Beginner
Beginner

Joined: Thu Aug 14, 2008 5:31 pm
Posts: 20
I think you are right regarding the Views. That should be the way to go.

But thinking about it, all my client databases should be exactely the same so I'm just going to normalise them, and that will solve the problem.

Thanks


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.