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.  [ 1 post ] 
Author Message
 Post subject: Can NH store a collection variable with value null?
PostPosted: Tue Jul 04, 2006 3:55 am 
Newbie

Joined: Thu May 04, 2006 4:23 am
Posts: 16
Location: Germany
Hi,

I don't like to use lazy instantiation of collection objects in properties (like in property contracts of class Costumer):

Code:
class Costumer
{
    ISet contracts
        get
        {
#if LAZY_INSTANTIATION
            if( m_constracts = null)
            {
                m_constracts = new ListSet();
            }
#endif
            return m_constracts;
        }
    }
    ISet m_constracts;

    Costumer()
    {
#if !LAZY_INSTANTIATION
        m_constracts = new ListSet();
#endif
    }

    ISet getContracts()
    {
        if (m_constracts = null)
        {
            m_constracts = new ListSet();
        }
        return m_constracts;
    }
}

because the C# debugger calls all get-methods of properties in the debugger (in pane "local variables"), which causes side effects.
That's why I only use methods to perform lazy instantiation (like "getContracts()" ).
[Or is there an option to switch of the automatic property evaluation in the debugger? An alternative would be an attribute "sideEffect" to mark such properties.]

Because I generate my code in partial class definitions, I can't instantiate the collection objects in the constructor (as in class Costumer) or in another central object initializiation method.

For my purposes it would be fine, if NH would interprete a null value in a collection variable (e.g. in "m_contracts") as an empty collection.
[A null value in a collection variable can only occur in a newly created object which is not already read from the database.]
Is this interpretation (of null value as empty collection) possible? - now? - maybe later?

Regards,
Mick


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.