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: Send NULL value when int property is 0.
PostPosted: Tue Sep 12, 2006 9:58 am 
Newbie

Joined: Sun Nov 20, 2005 10:23 am
Posts: 19
Hello,


There are possible, in mapping files, especifie that a int property don't must be persisted in database if it has a determined value (as 0), in this case the must be sended NULL to database.. This is possible?!


[]'s
FernandoVM


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 12, 2006 2:55 pm 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
You could create a custom user type that maps 0 to NULL and vice-versa. then your mapping files just specifies your custom user type. You could either inherit from NHibernate.Type.Int32Type, or implement NHibernate.IUserType from scratch. For our user types, we implemented the interface, and used composition rather than inheritance.

Using composition, we simply forwarded access to the SqlTypes property, DbTypes property, IsMutable method and DeepCopy method. Then just implement your own logic for the Equals, NullSafeSet and NullSafeGet methods. NullSafeSet and NullSafeGet can just map 0 to NULL and vice-versa before or after calling the base method, as appropriate. Equals can consider 0 equal to NULL.


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.