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: Non Virtual Calculated Properties
PostPosted: Wed Nov 05, 2008 5:02 pm 
Newbie

Joined: Tue Nov 04, 2008 5:02 pm
Posts: 4
I have a few objects in my framework that have calculated properties (i.e. properties that are not persisted to my data store and are calculated based on other properties of the object). I don't want to flag these properties as virtual (mainly because I don't want some developer coming along later and attempting to override them); however these properties must be public. I'm not including them in the my mapping file (since there is nothing in the data store to map them to) but if I don't flag them as virtual NHibernate still throws an exception ("The following types may not be used as proxies"). Is there a way to override this behavior?

Thanks

_________________
Shane A. McGarry
Senior Software Engineer


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 07, 2008 5:36 pm 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
You have to make them virtual because otherwise an uninitialized proxy won't know to initialize when the property is touched.

Even worse, we have some non-persisted properties that get assigned through our implementation of IInterceptor.Instantiate(). E.g. we assign a business rule object here that listens to property changes and reacts accordingly, because we don't want our entity classes to know about business rule classes directly (our entities only know the rule interface, which only exposes a method for the entity's ToString() method to call). The problem is that IInterceptor.Instantiate() does not get called when a a proxy is first created, but only when the proxy is initialized. So, when we initially tried to make these non-persisted properties non-virtual (because we didn't want reading the property to trigger initializing the proxy), the property would incorrectly return null because it was never initialized by the interceptor. We were forced to make these properties virtual to get the correct behavior.


Top
 Profile  
 
 Post subject: disable lazy load
PostPosted: Sun Nov 09, 2008 5:35 pm 
Newbie

Joined: Fri Oct 24, 2008 4:37 am
Posts: 11
Location: Planet earth
AFAIK you could disable lasy load of a class, forcing nhibernate to create all that is selected in a list.

_________________
With respect,
Morten


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.