-->
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: nullable property semantics
PostPosted: Wed Feb 20, 2008 6:38 pm 
Newbie

Joined: Wed Feb 20, 2008 6:28 pm
Posts: 1
in the mapping file for Content60 class:

Code:
    <many-to-one name="Policy" class="Entriq.Security.BusinessObject.Policy60, Entriq.Security.BusinessObject">
      <column name="PolicyRef" sql-type="bigint" not-null="true"/>
    </many-to-one>


the column PolicyRef is not-null in database. This cannot be changed.

Code:
        [Test]
        public void TestSaveDefPolicy()
        {
            BusinessSession.BeginTransaction();
            Content60 cContent = BusinessSession.ContentManager.Get(TestParameters.crmId,TestParameters.accountId,TestParameters.contentId);
            [b]cContent.Policy = null;[/b] // here we would like the PolicyRef column to equal "0", and not "null"
            cContent.ContentURL = "http://www.google.com?id=" + DateTime.Now.Ticks;
            cContent.Save();
            BusinessSession.CommitTransaction();

        }


correctly throws the following exception:

Entriq.MDS.Tests.Defects.SaveContentWithNullPolicy.TestSaveDefPolicy : NHibernate.PropertyValueException : not-null property references a null or transient value: Entriq.Security.BusinessObject.Content60.Policy

My question is as follows: how can I modify this scenario so that NHibernate will set the PolicyRef column to 0 when we set the Policy property to null?

Any help with how to achieve this in nhibernate is greatly appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 20, 2008 11:08 pm 
Beginner
Beginner

Joined: Mon Feb 04, 2008 1:48 pm
Posts: 30
Set a default value in your db table column to zero? Otherwise you could use IInterceptor.OnSave to check for null and set to zero. Or just set the property to zero rather then null.

Please rate or give credit if this helps. thx


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.