<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Must Everything Be Virtual With NHibernate, Part III</title>
	<atom:link href="http://davybrion.com/blog/2009/09/must-everything-be-virtual-with-nhibernate-part-iii/feed/" rel="self" type="application/rss+xml" />
	<link>http://davybrion.com/blog/2009/09/must-everything-be-virtual-with-nhibernate-part-iii/</link>
	<description>Trying to walk that thin line between intelligence and ignorance</description>
	<lastBuildDate>Wed, 08 Sep 2010 21:03:45 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Davy Brion</title>
		<link>http://davybrion.com/blog/2009/09/must-everything-be-virtual-with-nhibernate-part-iii/comment-page-1/#comment-22665</link>
		<dc:creator>Davy Brion</dc:creator>
		<pubDate>Thu, 08 Oct 2009 06:31:05 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1686#comment-22665</guid>
		<description>hmm, i&#039;m not entirely sure that the collections will still be lazy loaded if you set lazy=false</description>
		<content:encoded><![CDATA[<p>hmm, i&#8217;m not entirely sure that the collections will still be lazy loaded if you set lazy=false</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pavel</title>
		<link>http://davybrion.com/blog/2009/09/must-everything-be-virtual-with-nhibernate-part-iii/comment-page-1/#comment-22662</link>
		<dc:creator>Pavel</dc:creator>
		<pubDate>Wed, 07 Oct 2009 16:49:25 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1686#comment-22662</guid>
		<description>Thank you for answer. We will set Lazy = false on all of our objects. As understand it will prevent NHibernate from generatig proxy on our objects. Correct if I am wrong, collections of child objects will be still lazy loaded. The  difference will be that this collection will contains instances of object itself not proxies. I it right?</description>
		<content:encoded><![CDATA[<p>Thank you for answer. We will set Lazy = false on all of our objects. As understand it will prevent NHibernate from generatig proxy on our objects. Correct if I am wrong, collections of child objects will be still lazy loaded. The  difference will be that this collection will contains instances of object itself not proxies. I it right?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Davy Brion</title>
		<link>http://davybrion.com/blog/2009/09/must-everything-be-virtual-with-nhibernate-part-iii/comment-page-1/#comment-22661</link>
		<dc:creator>Davy Brion</dc:creator>
		<pubDate>Wed, 07 Oct 2009 04:53:02 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1686#comment-22661</guid>
		<description>I&#039;m not sure, but i don&#039;t think nhibernate keeps track of InternalsVisibleTo so i doubt that it will work</description>
		<content:encoded><![CDATA[<p>I&#8217;m not sure, but i don&#8217;t think nhibernate keeps track of InternalsVisibleTo so i doubt that it will work</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pavel</title>
		<link>http://davybrion.com/blog/2009/09/must-everything-be-virtual-with-nhibernate-part-iii/comment-page-1/#comment-22659</link>
		<dc:creator>Pavel</dc:creator>
		<pubDate>Tue, 06 Oct 2009 13:29:14 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1686#comment-22659</guid>
		<description>Thank you for replay. We use NHibernate for some time already. I got into trouble after trying upgrade to 2.1 release. My DAL objects has a few methods that marked as internal virtual. Idea behind it that I want restrict execution to my assemblies only for security reason. On top of it we obfuscate all internal marked stuff to add some extra trouble for people who wants to debug what we do. Now hibernate requires me to change all my

internal virtual SomeMethod(); into protected internal virtual and that I am trying to avoid doing this. I can make NHibernate to be &quot;friend&quot; of my assembly and in this case you should have no problem override my internal virtual stuff. Is it going to work?</description>
		<content:encoded><![CDATA[<p>Thank you for replay. We use NHibernate for some time already. I got into trouble after trying upgrade to 2.1 release. My DAL objects has a few methods that marked as internal virtual. Idea behind it that I want restrict execution to my assemblies only for security reason. On top of it we obfuscate all internal marked stuff to add some extra trouble for people who wants to debug what we do. Now hibernate requires me to change all my</p>
<p>internal virtual SomeMethod(); into protected internal virtual and that I am trying to avoid doing this. I can make NHibernate to be &#8220;friend&#8221; of my assembly and in this case you should have no problem override my internal virtual stuff. Is it going to work?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Davy Brion</title>
		<link>http://davybrion.com/blog/2009/09/must-everything-be-virtual-with-nhibernate-part-iii/comment-page-1/#comment-22656</link>
		<dc:creator>Davy Brion</dc:creator>
		<pubDate>Tue, 06 Oct 2009 06:24:58 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1686#comment-22656</guid>
		<description>@Pavel

you could just use the field access strategy</description>
		<content:encoded><![CDATA[<p>@Pavel</p>
<p>you could just use the field access strategy</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pavel</title>
		<link>http://davybrion.com/blog/2009/09/must-everything-be-virtual-with-nhibernate-part-iii/comment-page-1/#comment-22655</link>
		<dc:creator>Pavel</dc:creator>
		<pubDate>Tue, 06 Oct 2009 04:37:15 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1686#comment-22655</guid>
		<description>How can I code this example with NHibernate

public class SomeObject
{
       //Hibernate mapped field
       protected virtual EncryptedDatabaseField { get; set; }

       internal ClearTextField
       {
            get { return DecryptField(this.EncryptedDatabaseField); }
            set { this.EncryptedDatabaseField = EncryptField(value); }
       }
}

I simply trying to prevent see data ouside my assembly. If I will make ClearTextField &quot;protected internal virtual&quot; then it expose access to encryped database fields to anyone who can just simply subclass my class.</description>
		<content:encoded><![CDATA[<p>How can I code this example with NHibernate</p>
<p>public class SomeObject<br />
{<br />
       //Hibernate mapped field<br />
       protected virtual EncryptedDatabaseField { get; set; }</p>
<p>       internal ClearTextField<br />
       {<br />
            get { return DecryptField(this.EncryptedDatabaseField); }<br />
            set { this.EncryptedDatabaseField = EncryptField(value); }<br />
       }<br />
}</p>
<p>I simply trying to prevent see data ouside my assembly. If I will make ClearTextField &#8220;protected internal virtual&#8221; then it expose access to encryped database fields to anyone who can just simply subclass my class.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Davy Brion</title>
		<link>http://davybrion.com/blog/2009/09/must-everything-be-virtual-with-nhibernate-part-iii/comment-page-1/#comment-22640</link>
		<dc:creator>Davy Brion</dc:creator>
		<pubDate>Fri, 02 Oct 2009 06:43:59 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1686#comment-22640</guid>
		<description>@Thomas

it really all depends on what you prefer... the whole point is that you can do pretty much everything that you prefer, with some very minor (IMO) constraints ;)</description>
		<content:encoded><![CDATA[<p>@Thomas</p>
<p>it really all depends on what you prefer&#8230; the whole point is that you can do pretty much everything that you prefer, with some very minor (IMO) constraints <img src='http://davybrion.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Thomas Weller</title>
		<link>http://davybrion.com/blog/2009/09/must-everything-be-virtual-with-nhibernate-part-iii/comment-page-1/#comment-22639</link>
		<dc:creator>Thomas Weller</dc:creator>
		<pubDate>Fri, 02 Oct 2009 05:55:12 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1686#comment-22639</guid>
		<description>Sorry, but this discussion is largely pointless, and your code sample is not what I would call &lt;em&gt;best practice&lt;/em&gt;.
Just use interfaces together with the &lt;code&gt;proxy&lt;/code&gt; keyword in the mapping, and don&#039;t care about virtual or not virtual or some weird under-the-hood behaviour of dynamic proxies - it is a bad smell that the domain logic has to know about these issues at all!
And it&#039;s in my experience also much better to let NH populate fields directly (via &lt;code&gt;nosetter.camelcase&lt;/code&gt;) instead of using the relating properties, because the public properties of a business class will often have some additional validation or &lt;code&gt;PropertyChanged&lt;/code&gt; logic, which I don&#039;t want to be executed when only hydrating an entity from the DB. Besides all other things, this can lead to massive performance problems...
As you said, you also can hook your own IoC-Container into the proxy creation process, removing even the need for a default c&#039;tor. But I don&#039;t know yet if this is desirable in every case, since this may create other performance issues (IoC containers are very flexible, but also very slow...)

- Thomas</description>
		<content:encoded><![CDATA[<p>Sorry, but this discussion is largely pointless, and your code sample is not what I would call <em>best practice</em>.<br />
Just use interfaces together with the <code>proxy</code> keyword in the mapping, and don&#8217;t care about virtual or not virtual or some weird under-the-hood behaviour of dynamic proxies &#8211; it is a bad smell that the domain logic has to know about these issues at all!<br />
And it&#8217;s in my experience also much better to let NH populate fields directly (via <code>nosetter.camelcase</code>) instead of using the relating properties, because the public properties of a business class will often have some additional validation or <code>PropertyChanged</code> logic, which I don&#8217;t want to be executed when only hydrating an entity from the DB. Besides all other things, this can lead to massive performance problems&#8230;<br />
As you said, you also can hook your own IoC-Container into the proxy creation process, removing even the need for a default c&#8217;tor. But I don&#8217;t know yet if this is desirable in every case, since this may create other performance issues (IoC containers are very flexible, but also very slow&#8230;)</p>
<p>- Thomas</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Davy Brion</title>
		<link>http://davybrion.com/blog/2009/09/must-everything-be-virtual-with-nhibernate-part-iii/comment-page-1/#comment-22633</link>
		<dc:creator>Davy Brion</dc:creator>
		<pubDate>Tue, 29 Sep 2009 16:45:15 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1686#comment-22633</guid>
		<description>how could a dynamic proxy intercept a private property? you can&#039;t influence them through inheritance so the proxies can&#039;t do anything with them

1) i haven&#039;t looked into the non-castle proxy generators, but the one for castle only requires that every non-private member is virtual and that you have a default constructor (it doesn&#039;t even need to be public) 
2) you can actually use your own proxy factory and generator... there is out-of-the-box support for Castle, LinFu and Spring. If you want your own proxy generator, you just need to provide an implementation... though i&#039;m not entirely sure if all of the checks have been removed from the NHibernate codebase and have been moved into the specific proxy factories (though i guess they have been)</description>
		<content:encoded><![CDATA[<p>how could a dynamic proxy intercept a private property? you can&#8217;t influence them through inheritance so the proxies can&#8217;t do anything with them</p>
<p>1) i haven&#8217;t looked into the non-castle proxy generators, but the one for castle only requires that every non-private member is virtual and that you have a default constructor (it doesn&#8217;t even need to be public)<br />
2) you can actually use your own proxy factory and generator&#8230; there is out-of-the-box support for Castle, LinFu and Spring. If you want your own proxy generator, you just need to provide an implementation&#8230; though i&#8217;m not entirely sure if all of the checks have been removed from the NHibernate codebase and have been moved into the specific proxy factories (though i guess they have been)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andy Pook</title>
		<link>http://davybrion.com/blog/2009/09/must-everything-be-virtual-with-nhibernate-part-iii/comment-page-1/#comment-22631</link>
		<dc:creator>Andy Pook</dc:creator>
		<pubDate>Tue, 29 Sep 2009 14:01:18 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1686#comment-22631</guid>
		<description>OK. Better example.
But no reason you couldn&#039;t just use a private property though ?

The reason I keep coming back to this point is that we&#039;ve never needed this scenario. So making everything virtual has never seemed justifiable.
One of the reasons to switch to NHibernate is because of the very smart things it can do. But it&#039;s difficult to to warrant touching all the persisted classes to make everything virtual in order to support a scenario we don&#039;t (and probably won&#039;t) ever use.

Two questions if I may:
 1. Without studying the proxy generator. How do I gain some confidence that it &quot;does the right thing&quot; in _all_ circumstances?
 2. Presumably there&#039;s no reason why I can&#039;t fork my own proxy generator that conforms to my property only scheme. Should be _much_ simpler right?</description>
		<content:encoded><![CDATA[<p>OK. Better example.<br />
But no reason you couldn&#8217;t just use a private property though ?</p>
<p>The reason I keep coming back to this point is that we&#8217;ve never needed this scenario. So making everything virtual has never seemed justifiable.<br />
One of the reasons to switch to NHibernate is because of the very smart things it can do. But it&#8217;s difficult to to warrant touching all the persisted classes to make everything virtual in order to support a scenario we don&#8217;t (and probably won&#8217;t) ever use.</p>
<p>Two questions if I may:<br />
 1. Without studying the proxy generator. How do I gain some confidence that it &#8220;does the right thing&#8221; in _all_ circumstances?<br />
 2. Presumably there&#8217;s no reason why I can&#8217;t fork my own proxy generator that conforms to my property only scheme. Should be _much_ simpler right?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Davy Brion</title>
		<link>http://davybrion.com/blog/2009/09/must-everything-be-virtual-with-nhibernate-part-iii/comment-page-1/#comment-22625</link>
		<dc:creator>Davy Brion</dc:creator>
		<pubDate>Mon, 28 Sep 2009 18:14:41 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1686#comment-22625</guid>
		<description>What if i don&#039;t want to publicly expose certain values outside of my entity? You could argue that you could do that with protected automatic properties, but what if i don&#039;t want those values to be available to derived classes either?

Regardless of what your personal preferences are, people will use backing fields for various reasons in their entities.  The possibility of not initializing lazy-loaded values because of that, is something that an ORM should prevent.

&quot;It has always just struck me as odd that I need to open up the API to my classes to satisfy the ORM.&quot;

i find it just as odd that i would need to open up the data of my classes to _everyone_ because of a limitation in an ORM ;)</description>
		<content:encoded><![CDATA[<p>What if i don&#8217;t want to publicly expose certain values outside of my entity? You could argue that you could do that with protected automatic properties, but what if i don&#8217;t want those values to be available to derived classes either?</p>
<p>Regardless of what your personal preferences are, people will use backing fields for various reasons in their entities.  The possibility of not initializing lazy-loaded values because of that, is something that an ORM should prevent.</p>
<p>&#8220;It has always just struck me as odd that I need to open up the API to my classes to satisfy the ORM.&#8221;</p>
<p>i find it just as odd that i would need to open up the data of my classes to _everyone_ because of a limitation in an ORM <img src='http://davybrion.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andy Pook</title>
		<link>http://davybrion.com/blog/2009/09/must-everything-be-virtual-with-nhibernate-part-iii/comment-page-1/#comment-22623</link>
		<dc:creator>Andy Pook</dc:creator>
		<pubDate>Mon, 28 Sep 2009 17:00:53 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=1686#comment-22623</guid>
		<description>Lame workaround, hmmm...

I would still argue that the example is a little contrived to support the point. If I was reviewing this code I would say that the Customer property should be an auto-property like the rest.
I would argue that, in this code, referring to the backing field is a bug/smell/bad practice.

It has always just struck me as odd that I need to open up the API to my classes to satisfy the ORM.

I also find it hard to agree with your last point about blaming the ORM. I would suggest that these case were backing fields are accessed are smells. I would be looking to see where my code wasn&#039;t conforming to the correct conventions not blaming the ORM for not being clever enough.

I&#039;m playing devils advocate here. I am willing to be convinced.</description>
		<content:encoded><![CDATA[<p>Lame workaround, hmmm&#8230;</p>
<p>I would still argue that the example is a little contrived to support the point. If I was reviewing this code I would say that the Customer property should be an auto-property like the rest.<br />
I would argue that, in this code, referring to the backing field is a bug/smell/bad practice.</p>
<p>It has always just struck me as odd that I need to open up the API to my classes to satisfy the ORM.</p>
<p>I also find it hard to agree with your last point about blaming the ORM. I would suggest that these case were backing fields are accessed are smells. I would be looking to see where my code wasn&#8217;t conforming to the correct conventions not blaming the ORM for not being clever enough.</p>
<p>I&#8217;m playing devils advocate here. I am willing to be convinced.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
