-->
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: Why Restrict all Class Member to be virtual?
PostPosted: Sun Dec 09, 2007 3:18 am 
Newbie

Joined: Fri Sep 22, 2006 3:04 am
Posts: 5
I just cann't imagine how could this be done?
Just proxy the persist-related Properties or Fields I think it's enough.
please please give me replay just tell me why?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 10, 2007 5:00 am 
Regular
Regular

Joined: Fri Feb 18, 2005 3:34 am
Posts: 88
Location: Poland/Wrocław
This is a requirement of Castle.DynamicProxy proxy generation tool. Furthermore, if you turn off lazy loading on a class then it does not need to be constrained this way. AFAIR you will lalso need to switch off checking for virtualization of members then.

_________________
Please rate this post if you've found it helpfull
Roland


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 10, 2007 9:44 am 
Senior
Senior

Joined: Thu Feb 09, 2006 1:30 pm
Posts: 172
If you set lazy="false" on the class you do not need to do anything else. You will no longer see this issue since a proxy will not be created for you object.

You need virtual due to how NHibernate does lazy classes. Basically it created a proxy (using the Castle DynamicProxy) object which inherits from your class. Whenever it would have created your Order class for example, it creates an OrderProxy instead. Then it needs all properties and methods to be virtual since it wraps them in its own methods which first ensure that the object has been loaded and then calls your method. The only way to override your properties or methods to perform this check is if they are virtual.

Note that the decision to make all properties and methods as virtual is a mistake in my opinion. In the Java world everything is virtual by default unless you say otherwise. In the C# world it's the exact opposite. There is a minor performance hit to using virtual members, but it is not one that is likely to be noticed.


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.