<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Symbiotic Development &#187; NHibernate</title>
	<atom:link href="http://blog.symbiotic-development.com/category/nhibernate/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.symbiotic-development.com</link>
	<description>Evolving Together</description>
	<lastBuildDate>Mon, 27 Oct 2008 15:43:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>NHibernate ProxyGenerators added to NHContrib</title>
		<link>http://blog.symbiotic-development.com/2008/09/23/nhibernate-proxygenerators-added-to-nhcontrib/</link>
		<comments>http://blog.symbiotic-development.com/2008/09/23/nhibernate-proxygenerators-added-to-nhcontrib/#comments</comments>
		<pubDate>Tue, 23 Sep 2008 06:55:58 +0000</pubDate>
		<dc:creator>Symon Rottem</dc:creator>
				<category><![CDATA[NHibernate]]></category>

		<guid isPermaLink="false">http://blog.symbiotic-development.com/2008/09/23/nhibernate-proxygenerators-added-to-nhcontrib/</guid>
		<description><![CDATA[It looks like the NHibernate Proxy Generator I discussed in a previous post has been added to the NHibernateForge, the NHibernate community and contribution site. This is great news for those of you who are stuck in a medium trust environment and are having problems with lazy loading &#8211; if you need it then check [...]]]></description>
			<content:encoded><![CDATA[<p>It looks like the NHibernate Proxy Generator I discussed in a <a href="http://blog.symbiotic-development.com/2008/03/22/nhibernate-proxy-generator/">previous post</a> has been added to the <a href="http://www.nhforge.org/" target="_blank">NHibernateForge</a>, the NHibernate community and contribution site.</p>
<p>This is great news for those of you who are stuck in a medium trust environment and are having problems with lazy loading &#8211; if you need it then <a href="http://www.nhforge.org/media/g/proxygenerators/default.aspx" target="_blank">check it out</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.symbiotic-development.com/2008/09/23/nhibernate-proxygenerators-added-to-nhcontrib/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>NHibernate 2.0 Beta 2 Released</title>
		<link>http://blog.symbiotic-development.com/2008/07/13/nhibernate-20-beta-2-released/</link>
		<comments>http://blog.symbiotic-development.com/2008/07/13/nhibernate-20-beta-2-released/#comments</comments>
		<pubDate>Sun, 13 Jul 2008 16:57:22 +0000</pubDate>
		<dc:creator>Symon Rottem</dc:creator>
				<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://blog.symbiotic-development.com/2008/07/13/nhibernate-20-beta-2-released/</guid>
		<description><![CDATA[For those not watching the mailing list a new beta release of NHibernate 2.0 was released today and word is that if no major issues show up the first release candidate will be made available in another two weeks. This is a fantastic announcement and although the alphas and betas have been pretty damned good [...]]]></description>
			<content:encoded><![CDATA[<p>For those not watching the mailing list a new beta release of NHibernate 2.0 was released today and word is that if no major issues show up the first release candidate will be made available in another two weeks.</p>
<p>This is a fantastic announcement and although the alphas and betas have been pretty damned good it&#8217;s nice to see that things are underway for a production release in the not too distant future &#8211; a nice thing to see in any open source project.</p>
<p>Exellent work and kudos to Fabio Maulo and the rest of the team working on the project!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.symbiotic-development.com/2008/07/13/nhibernate-20-beta-2-released/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>NHibernate 2.0 Alpha 2 Released</title>
		<link>http://blog.symbiotic-development.com/2008/06/21/nhibernate-20-alpha-2-released/</link>
		<comments>http://blog.symbiotic-development.com/2008/06/21/nhibernate-20-alpha-2-released/#comments</comments>
		<pubDate>Sat, 21 Jun 2008 07:56:27 +0000</pubDate>
		<dc:creator>Symon Rottem</dc:creator>
				<category><![CDATA[NHibernate]]></category>

		<guid isPermaLink="false">http://blog.symbiotic-development.com/2008/06/21/nhibernate-20alpha2-released/</guid>
		<description><![CDATA[For those not in the know, another alpha release of NHibernate 2.0 was pushed out almost a week ago. Oddly enough I missed that this had come out &#8211; it doesn&#8217;t appear to have been announced on the NHibernate forums&#8230;it did show up on the NHibernate mailing list, however. The new release addresses a host [...]]]></description>
			<content:encoded><![CDATA[<p>For those not in the know, another alpha release of NHibernate 2.0 was pushed out almost a week ago.  Oddly enough I missed that this had come out &#8211; it doesn&#8217;t appear to have been announced on the NHibernate forums&#8230;it did show up on the NHibernate mailing list, however.</p>
<p>The new release addresses a host of bugs and rolls in a couple of improvements.  The changelog can be found <a href="http://jira.nhibernate.org/secure/ReleaseNote.jspa?projectId=10000&amp;styleName=Html&amp;version=10190" target="_blank">here</a>.</p>
<p>If you get a chance <a href="http://sourceforge.net/project/showfiles.php?group_id=73818" target="_blank">grab the new release</a> and give it a spin.  The developers are looking for feedback and the more the community uses the latest release the more likely we are to see a release candidate in the near future.  If you find a bug it can be reported on NHibernate&#8217;s Jira at its <a href="http://jira.nhibernate.org/secure/Dashboard.jspa" target="_blank">new location</a>.</p>
<p>A big thanks should go to Fabio Maulo for his excellent work in leading this project.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.symbiotic-development.com/2008/06/21/nhibernate-20-alpha-2-released/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>NHibernate 2.0 Alpha</title>
		<link>http://blog.symbiotic-development.com/2008/03/31/nhibernate-20-alpha/</link>
		<comments>http://blog.symbiotic-development.com/2008/03/31/nhibernate-20-alpha/#comments</comments>
		<pubDate>Mon, 31 Mar 2008 21:41:05 +0000</pubDate>
		<dc:creator>Symon Rottem</dc:creator>
				<category><![CDATA[NHibernate]]></category>

		<guid isPermaLink="false">http://blog.symbiotic-development.com/2008/03/31/nhibernate-20-alpha/</guid>
		<description><![CDATA[For those of you who aren&#8217;t already in the know, the new version of NHibernate has entered it&#8217;s alpha release stage. This brings the codebase almost into line with the current Java Hibernate release (3.2) with a couple of exceptions so this is definitely something to write home about. A few of the key things [...]]]></description>
			<content:encoded><![CDATA[<p>For those of you who aren&#8217;t already in the know, the new version of NHibernate has entered it&#8217;s alpha release stage.  This brings the codebase almost into line with the current Java Hibernate release (3.2) with a couple of exceptions so this is definitely something to write home about.</p>
<p>A few of the key things that I&#8217;ve been waiting for in this release are:</p>
<ul>
<li>Inspection/traversal, modification and cloning of ICriteria</li>
<li>Table per subclass mapping with a discriminator</li>
<li>MultiCriteria</li>
<li>Mapping of one class to several tables using the<em><strong> </strong>&lt;join&gt;</em> mapping.</li>
<li><span class="postbody">Events and listeners     </span></li>
</ul>
<p>The <a href="http://sourceforge.net/project/shownotes.php?release_id=588327&amp;group_id=73818" target="_blank">changelog</a> goes some of the way to explain the new changes in more detail than I have, but there&#8217;s a more comprehensive rundown on <a href="http://www.ayende.com/Blog/archive/2008/03/31/NHibernate-2.0-Alpha-is-out.aspx" target="_blank">Ayende&#8217;s blog</a> if you want a little more meat to chew on.  In addition, Fabio Maulo (one of the NHibernate developers) noted that there are a couple of additional features that are notably missing from the changelog; namely the Merge and Persist methods on ISession and extended cascade mappings, unionsubclass and on-delete on the mapping side.</p>
<p>In reality you do need to take some care before upgrading since this is an alpha, but you can rest assured that the code is <em>not</em> brand spanking new, untested and unused.  As Ayende mentions in his blog post&#8230;</p>
<blockquote><p> We call this alpha, but many of us are using this in production, so we are really certain in its stability.</p></blockquote>
<p>Anway, the call is out to start playing with the new version so the developers can get some real-world feedback on how it&#8217;s working in <em>your</em> environment and a chance to fix any issues before they give it their blessing for use in more critical and widespread environments. The Castle trunk has been updated to use this new release, so it can&#8217;t be too bad now, can it?</p>
<p>If you do decide to upgrade there are some <a href="http://forum.hibernate.org/viewtopic.php?t=985289&amp;sid=849a2c6f299e33ae23c36e25e29aafd6" target="_blank">breaking changes</a> to be aware of, but most of them shouldn&#8217;t cause you major problems unless you&#8217;ve decided to bend and twist NHibernate more that the average user.</p>
<p>Also worthy of note is that there don&#8217;t appear to be updated docs available yet, but since most of the features of the new version match those of the production Java version <a href="http://www.hibernate.org/hib_docs/v3/reference/en/html_single/" target="_blank">their docs</a> should help you get a good idea of where you are going.</p>
<p>You can keep up with what&#8217;s going on with others who are using the new version, get help and can provide feedback on the new <a href="http://groups.google.com/group/nhusers" target="_blank">NHibernate mailing list</a> as well as the <a href="http://forum.hibernate.org/viewforum.php?f=25" target="_blank">forums</a>.  At the moment the mailing list is very active so it&#8217;s a great alternative to the forums if you don&#8217;t get any response there.</p>
<p>I&#8217;ll be taking the new NHibernate for a whirl myself very shortly and will post on my experiences as they happen.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.symbiotic-development.com/2008/03/31/nhibernate-20-alpha/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NHibernate Proxy Generator</title>
		<link>http://blog.symbiotic-development.com/2008/03/22/nhibernate-proxy-generator/</link>
		<comments>http://blog.symbiotic-development.com/2008/03/22/nhibernate-proxy-generator/#comments</comments>
		<pubDate>Sat, 22 Mar 2008 15:11:20 +0000</pubDate>
		<dc:creator>Symon Rottem</dc:creator>
				<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[]]></category>
		<category><![CDATA[Lazy Loading]]></category>
		<category><![CDATA[NHibernate Proxy Generator]]></category>
		<category><![CDATA[NPG]]></category>

		<guid isPermaLink="false">http://blog.symbiotic-development.com/2008/03/22/nhibernate-proxy-generator/</guid>
		<description><![CDATA[I just stumbled over an interesting post on William C. Pierce&#8216;s blog explaining how to set up NHibernate to run in a a medium trust environment and still get the benefits of lazy loading. I&#8217;ve seen a few queries about how to do use lazy loading under medium trust in the past but have never [...]]]></description>
			<content:encoded><![CDATA[<p>I just stumbled over an interesting post on <a href="http://blechie.com/WPierce" target="_blank">William C. Pierce</a>&#8216;s blog explaining how to set up NHibernate to run in a a medium trust environment and still get the benefits of lazy loading.</p>
<p>I&#8217;ve seen a few queries about how to do use lazy loading under medium trust in the past but have never really investigated it myself having assumed it was just one of those things you couldn&#8217;t do since proxies are generated through reflection and reflection permissions are not granted in medium trust environments.</p>
<p>Well it turns out that isn&#8217;t the case if you get a little creative.</p>
<p>What William has done is to create his own proxy factory that NHibernate can be configured to use so it will provide proxies that were generated at compile time where you have full trust rather than generating proxies at runtime where the reflection permissions are restricted.<br />
He&#8217;s also provided a tool to generate those compile time proxies and released his hours of hard work as the <a href="http://code.google.com/p/nhibernateproxygenerator/" target="_blank">NHibernate Proxy Generator</a> (or NPG) so you don&#8217;t have to invest time of your own.  The project is still in it&#8217;s infancy but it&#8217;s released under the Apache License 2.0 so you can download the source and contribute should you so desire.</p>
<p>William has provided more information on how NHibernate can be configured to run in medium trust and use NPG generated proxies in his <a href="http://blechie.com/WPierce/archive/2008/02/17/Lazy-Loading-with-nHibernate-Under-Medium-Trust.aspx" target="_blank">blog post</a> so head on over there if you&#8217;re stuck with medium trust and still need lazy loading.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.symbiotic-development.com/2008/03/22/nhibernate-proxy-generator/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>More Configuring NHibernate Caches</title>
		<link>http://blog.symbiotic-development.com/2008/02/27/more-configuring-nhibernate-caches/</link>
		<comments>http://blog.symbiotic-development.com/2008/02/27/more-configuring-nhibernate-caches/#comments</comments>
		<pubDate>Wed, 27 Feb 2008 11:52:09 +0000</pubDate>
		<dc:creator>Symon Rottem</dc:creator>
				<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[ORM]]></category>
		<category><![CDATA[SysCache]]></category>

		<guid isPermaLink="false">http://blog.symbiotic-development.com/2008/02/27/more-configuring-nhibernate-caches/</guid>
		<description><![CDATA[One of my readers recently asked to see a sample of configuring NHibernate caching through the config file after reading my previous post Configuring NHibernate Caches, so here goes. Please bear with me in case there are any typos as this has been rolled by hand. In this particular example I&#8217;m configuring NHibernate to use [...]]]></description>
			<content:encoded><![CDATA[<p>One of my readers recently asked to see a sample of configuring NHibernate caching through the config file after reading my previous post <a href="http://blog.symbiotic-development.com/2008/02/09/configuring-nhibernate-caches/">Configuring NHibernate Caches</a>, so here goes.  Please bear with me in case there are any typos as this has been rolled by hand.</p>
<p>In this particular example I&#8217;m configuring NHibernate to use SysCache for the second level cache and have done it all in the app.config (or web.config if it&#8217;s a web application).   Note that this is not a fully complete config file but deals with the parts necessary for this example.</p>
<pre class="brush: xml;">

&lt;configuration&gt;

&lt;configsections&gt;
&lt;section name=&quot;hibernate-configuration&quot; type=&quot;NHibernate.Cfg.ConfigurationSectionHandler, NHibernate&quot;/&gt;
&lt;section name=&quot;syscache&quot; type=&quot;NHibernate.Caches.SysCache.SysCacheSectionHandler,NHibernate.Caches.SysCache&quot;/&gt;
&lt;/configsections&gt;

&lt;!--
NHibernate specific configuration.
--&gt;
&lt;hibernate-configuration xmlns=&quot;urn:nhibernate-configuration-2.2&quot;&gt;

&lt;session-factory&gt;

&lt;property name=&quot;hibernate.connection.connection_string&quot;&gt;Your Connection String&lt;/property&gt;
&lt;property name=&quot;hibernate.connection.provider&quot;&gt;NHibernate.Connection.DriverConnectionProvider&lt;/property&gt;
&lt;property name=&quot;hibernate.dialect&quot;&gt;NHibernate.Dialect.MsSql2000Dialect&lt;/property&gt;
&lt;property name=&quot;hibernate.connection.driver_class&quot;&gt;NHibernate.Driver.SqlClientDriver&lt;/property&gt;
&lt;property name=&quot;hibernate.connection.isolation&quot;&gt;ReadCommitted&lt;/property&gt;
&lt;property name=&quot;hibernate.cache.provider_class&quot;&gt;NHibernate.Caches.SysCache.SysCacheProvider, NHibernate.Caches.SysCache&lt;/property&gt;
&lt;property name=&quot;hibernate.cache.use_query_cache&quot;&gt;true&lt;/property&gt;

&lt;!--
Sets up class and configuration caching for domain classes.
These cache definitions can be tweaked to change how each class is cached.
--&gt;
&lt;class-cache class=&quot;Core.User, Core&quot; region=&quot;User&quot; usage=&quot;read-write&quot;/&gt;
&lt;collection-cache collection=&quot;Core.User.Roles&quot; region=&quot;User.Roles&quot; usage=&quot;read-write&quot;/&gt;

&lt;class-cache class=&quot;Core.Role, Core&quot; region=&quot;Role&quot; usage=&quot;read-write&quot;/&gt;

&lt;/session-factory&gt;

&lt;/hibernate-configuration&gt;

&lt;!--
Defines Syscache specific configuration
--&gt;
&lt;syscache&gt;

&lt;!-- Class cache regions --&gt;
&lt;cache region=&quot;User&quot; expiration=&quot;60&quot; priority=&quot;3&quot;/&gt;
&lt;cache region=&quot;User.Roles&quot; expiration=&quot;60&quot; priority=&quot;3&quot;/&gt;
&lt;cache region=&quot;Role&quot; expiration=&quot;60&quot; priority=&quot;3&quot;/&gt;

&lt;/syscache&gt;

&lt;/configuration&gt;
</pre>
<p>To explain this in a little more detail, the first section deals with telling the application about the configuration sections that will be included in the config file and what handlers to use to interpret them.  This is really just standard .NET confg stuff:</p>
<pre class="brush: xml;">

&lt;configsections&gt;
&lt;section name=&quot;hibernate-configuration&quot; type=&quot;NHibernate.Cfg.ConfigurationSectionHandler, NHibernate&quot;/&gt;
&lt;section name=&quot;syscache&quot; type=&quot;NHibernate.Caches.SysCache.SysCacheSectionHandler,NHibernate.Caches.SysCache&quot;/&gt;
&lt;/configsections&gt;
</pre>
<p>Then we deal with the main NHibernate configuration inside the <em>hibernate-configuration </em>section specified in the configsections:</p>
<pre class="brush: xml;">

&lt;property name=&quot;hibernate.connection.connection_string&quot;&gt;Your Connection String&lt;/property&gt;
&lt;property name=&quot;hibernate.connection.provider&quot;&gt;NHibernate.Connection.DriverConnectionProvider&lt;/property&gt;
&lt;property name=&quot;hibernate.dialect&quot;&gt;NHibernate.Dialect.MsSql2000Dialect&lt;/property&gt;
&lt;property name=&quot;hibernate.connection.driver_class&quot;&gt;NHibernate.Driver.SqlClientDriver&lt;/property&gt;
&lt;property name=&quot;hibernate.connection.isolation&quot;&gt;ReadCommitted&lt;/property&gt;
&lt;property name=&quot;hibernate.cache.provider_class&quot;&gt;NHibernate.Caches.SysCache.SysCacheProvider, NHibernate.Caches.SysCache&lt;/property&gt;
&lt;property name=&quot;hibernate.cache.use_query_cache&quot;&gt;true&lt;/property&gt;
</pre>
<p>The key things to note here are the <em>hibernate.cache.provider_class</em> and <em>hibernate.cache.use_query_cache</em> properties which are indicating that we should be using the SysCacheProvider for caching and that the query cache should be enabled.</p>
<p>It&#8217;s important to note that just adding the <em>hibernate.cache.provider_class</em> property and configuring some of your classes will cause those classes to be put into the second level <em>class cache</em> so that when you attempt to load them using ISession.Get or ISession.Load the the database will only be hit if the matching entity is not found in the cache.</p>
<p>What it will <strong>not </strong>do, however, is provide any optimisation when you attempt to load entities using an HQL or ICriteria query.  Queries will still go to the database to get their results unless, of course, you add the <em>hibernate.cache.use_query_cache</em> property to your configuration and explicitly specify that a query should be cachable using the IQuery.SetCachable(true) method &#8211; this must be done explicitly for each query you want to be cached.</p>
<p>When a query is cached the entity IDs in the results of a query will be stored along with the query itself in the second level <em>query cache</em> so that if it&#8217;s executed again it will take the list of IDs from the cache and will then re-hydrate the entities from the class cache. Because of this the query cache is useless without the class cache.</p>
<p>The next section deals with configuring the how each class should be cached.  This is still part of the <em>hibernate </em>config section:</p>
<pre class="brush: xml;">

&lt;!--
Sets up class and configuration caching for domain classes.
These cache definitions can be tweaked to change how each class is cached.
--&gt;
&lt;class-cache class=&quot;Core.User, Core&quot; region=&quot;User&quot; usage=&quot;read-write&quot;/&gt;
&lt;collection-cache collection=&quot;Core.User.Roles&quot; region=&quot;User.Roles&quot; usage=&quot;read-write&quot;/&gt;

&lt;class-cache class=&quot;Core.Role, Core&quot; region=&quot;Role&quot; usage=&quot;read-only&quot;/&gt;
</pre>
<p>Essentially there are two separate caching definitions to work with; the <em>class-cache</em> element, which deals with how a specific entity type should be cached and the <em>collection-cache</em> element that specifies how an entity&#8217;s dependent collection should be cached.</p>
<p>In this example I have elected to cache my User and Role entities as well as the Roles collection on the User entity.</p>
<p>Note that for each mapping you can specify a cache <em>region</em>, which provides additional granularity regarding how specific types should be expired from the cache and a <em>usage </em>that can provide some additional optimization based on whether or not the entities will ever be updated or new entities created by the application.</p>
<p>The final section of my example deals specifically with configuring the SysCache caching provider:</p>
<pre class="brush: xml;">
&lt;!--
Defines Syscache specific configuration
--&gt;
&lt;syscache&gt;

&lt;!-- Class cache regions --&gt;
&lt;cache region=&quot;User&quot; expiration=&quot;60&quot; priority=&quot;3&quot;/&gt;
&lt;cache region=&quot;User.Roles&quot; expiration=&quot;60&quot; priority=&quot;3&quot;/&gt;
&lt;cache region=&quot;Role&quot; expiration=&quot;86400&quot; priority=&quot;3&quot;/&gt;

&lt;/syscache&gt;
</pre>
<p>Here you can define the cache regions used in the class-cache and collection-cache mappings above as well as any cache regions you decide to use in queries inside your application.  Each cache region describes how long items in that region should stay in the cache before being expired so they will be reloaded again from the database and a priority that indicates which classes should be expired from memory first if the available memory is getting too low.</p>
<p>You can, of course, dump everything into a single cache region, but then all entities will be treated equally in the cache.  In my case I want the User entities and their Roles collections to be cached for one minute as this information could be updated externally and I want to have the changes reflected in the application fairly quickly.  The Role entities, however, will hardly ever change so I&#8217;ve chosen to cache them for a whole day before they should be re-obtained from the database.</p>
<p>Hopefully that clears things up a bit.  If there are any questions or comments please feel free to post one &#8211; don&#8217;t be shy!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.symbiotic-development.com/2008/02/27/more-configuring-nhibernate-caches/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Duplicate Madness</title>
		<link>http://blog.symbiotic-development.com/2008/02/21/duplicate-madness/</link>
		<comments>http://blog.symbiotic-development.com/2008/02/21/duplicate-madness/#comments</comments>
		<pubDate>Thu, 21 Feb 2008 21:08:03 +0000</pubDate>
		<dc:creator>Symon Rottem</dc:creator>
				<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[ORM]]></category>
		<category><![CDATA[Collections]]></category>
		<category><![CDATA[Duplicates]]></category>

		<guid isPermaLink="false">http://blog.symbiotic-development.com/2008/02/21/duplicate-madness/</guid>
		<description><![CDATA[One of the things that really kills me in NHibernate is the way that when using joins there are often duplicated entities in the result set. The thing that set me off today is a thread I got involved in on the NHiberate forums where the poster was getting what appeared to be bizarre entity [...]]]></description>
			<content:encoded><![CDATA[<p>One of the things that really kills me in NHibernate is the way that when using joins there are often duplicated entities in the result set.  The thing that set me off today is a thread I got involved in on the NHiberate forums where the poster was getting what appeared to be bizarre entity duplication in a list property of an object retreived using ISession.Get.</p>
<p>In this particular case the model was&#8230;</p>
<pre>Person -&lt; Order -&lt; OrderItem</pre>
<p>&#8230;where each Person had multiple Orders and each Order had multiple OrderItems.  Each of the collections (Person.Orders and Order.OrderItems) had been mapped as bags and for performance reasons (presumably appropriate to their context) the chosen fetch strategy for the collections was  set to fetch=&#8221;join&#8221;.</p>
<p>Everyone with me so far?</p>
<p>The problem here is that if you perform an ISession.Get on a Person who has 1 Order and that Order has 3 OrderItems the Person.Orders collection will contain 3 of the same Order.  Why?  Well this stems from the way the underlying result set returned by the database works &#8211; NHibernate formulates a query with joins in it to get all the data in one go (since that&#8217;s what we asked for).</p>
<p>The SQL query for ISession.Get(typeof(Person), 300) would look something like this (select clause omitted for brevity):</p>
<pre class="brush: sql;">...FROM Person p INNER JOIN Orders o ON o.PersonId = p.Id INNER JOIN OrderItems i ON i.OrderId = o.Id WHERE p.Id =300;</pre>
<p>(Note that this is hand rolled. And they might not be inner joins, but you get the idea.)</p>
<p>Using our scenario of a Person with 1 Order which has 3 OrderItems from above the result set might look like this:</p>
<table>
<tr>
<td style="border: 1px solid #000000">p.Id</td>
<td style="border: 1px solid #000000">p.Name</td>
<td style="border: 1px solid #000000">o.Id</td>
<td style="border: 1px solid #000000">o.PersonId</td>
<td style="border: 1px solid #000000">o.Date</td>
<td style="border: 1px solid #000000">i.Id</td>
<td style="border: 1px solid #000000">i.OrderId</td>
<td style="border: 1px solid #000000">i.Description</td>
</tr>
<tr>
<td style="border: 1px solid #000000">300</td>
<td style="border: 1px solid #000000">Symon</td>
<td style="border: 1px solid #000000">595</td>
<td style="border: 1px solid #000000">300</td>
<td style="border: 1px solid #000000">21/02/2008</td>
<td style="border: 1px solid #000000">9876</td>
<td style="border: 1px solid #000000">595</td>
<td style="border: 1px solid #000000">Fishing Rod</td>
</tr>
<tr>
<td style="border: 1px solid #000000">300</td>
<td style="border: 1px solid #000000">Symon</td>
<td style="border: 1px solid #000000">595</td>
<td style="border: 1px solid #000000">300</td>
<td style="border: 1px solid #000000">21/02/2008</td>
<td style="border: 1px solid #000000">9877</td>
<td style="border: 1px solid #000000">595</td>
<td style="border: 1px solid #000000">Hat</td>
</tr>
<tr>
<td style="border: 1px solid #000000">300</td>
<td style="border: 1px solid #000000">Symon</td>
<td style="border: 1px solid #000000">595</td>
<td style="border: 1px solid #000000">300</td>
<td style="border: 1px solid #000000">21/02/2008</td>
<td style="border: 1px solid #000000">9878</td>
<td style="border: 1px solid #000000">595</td>
<td style="border: 1px solid #000000">Boat</td>
</tr>
</table>
<p>Now, you see the Get operation only returns one Person object but the Orders collection is populated from the result set and there are 3 rows there that contain order information so 3 order items are added to the collection.</p>
<p>Now it&#8217;s not quite as bad as it looks.  The database operation was efficient because we didn&#8217;t have to go to the database multiple times and if you&#8217;re thinking we&#8217;re using up a chunk of extra memory with the unwanted extra Order items you&#8217;d be wrong &#8211; the list contains 3 references to the same object in memory, so there&#8217;s really only one Order there.</p>
<p>In this particular example the duplicates would not be there if the collections were mapped as Sets rather than Bags.  This is because a Set does not allow duplicates so they are filtered out when they&#8217;re added.</p>
<p>A more likely situation where you&#8217;re going to see this behavior is where you use the default fetch strategy in your mapping but you execute an HQL or ICriteria query with a join:</p>
<pre class="brush: sql;">.SELECT k FROM Cat c WHERE INNER JOIN c.Kittens k WHERE c.Colour = :ParentColour AND k.Colour = :KittenColour</pre>
<p>When you call the IQuery.List() method this will return a list of Kitten entities, but since there can be more than one Cat that has the same Kitten in their Kittens collection (Mummy and Daddy, right?) the same Kitten may show up more than once in the result set.</p>
<p>This is, apparently, behavior by design.  When the original Hibernate (Java version) developers were making decisions they felt that it made more sense for the returned objects to match the result set &#8211; I can&#8217;t remember the post I read it from since it was more than a year ago now, so I might not have this exactly right and I&#8217;d be happy for someone to correct me.</p>
<p>Again, the solution is to feed the results of the returned IList into a set which will remove the duplicates for you.  There is also a feature on the ICriteria API that allows you to provide a result set transformer too &#8211; if you don&#8217;t believe me you can re-read the documentation&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.symbiotic-development.com/2008/02/21/duplicate-madness/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>O/R Mapper Choices</title>
		<link>http://blog.symbiotic-development.com/2008/02/12/or-mapper-choices/</link>
		<comments>http://blog.symbiotic-development.com/2008/02/12/or-mapper-choices/#comments</comments>
		<pubDate>Tue, 12 Feb 2008 20:11:55 +0000</pubDate>
		<dc:creator>Symon Rottem</dc:creator>
				<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[ORM]]></category>
		<category><![CDATA[Transparent Persistence]]></category>

		<guid isPermaLink="false">http://blog.symbiotic-development.com/2008/02/12/or-mapper-choices/</guid>
		<description><![CDATA[I saw this article by Mario Van Damme the other day about some of the decisions you should probably take into account when choosing an Object Relational mapping tool. Best Practices for Object/Relational Mapping and Persistence APIs Although published in 2006 it&#8217;s a good article on some of the considerations that I didn&#8217;t take into [...]]]></description>
			<content:encoded><![CDATA[<p>I saw this article by <a href="http://www.developerdotstar.com/mag/bios/mario_van_damme.html">Mario Van Damme</a> the other day about some of the decisions you should probably take into account when choosing an Object Relational mapping tool.</p>
<p><strong><a href="http://www.developerdotstar.com/mag/articles/o-r_mapping_persistence.html"> Best Practices for Object/Relational Mapping and Persistence APIs</a></strong></p>
<p>Although published in 2006 it&#8217;s a good article on some of the considerations that I <em>didn&#8217;t </em>take into account when choosing an ORM and probably should have.  Luckily, NHibernate has worked out as a good choice overall</p>
<p>Mind you, when I started with NHibernate I did struggle against transparent persistence &#8211; to my mind I should have full control over when all persistence actions take place, so I did everything I could to disable transparent persistence &#8211; to my detriment.  That said, I&#8217;ve learned from my mistakes and have fully embraced NHibernate&#8217;s transparent persistence and transactions and all the performance advantages it provides, however there have certainly been some projects where an persistence solution that allows me full control would have been a better choice.</p>
<p>Had I read the Mario&#8217;s article I might have had some idea of where I was going before I started.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.symbiotic-development.com/2008/02/12/or-mapper-choices/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DDD and NHibernate</title>
		<link>http://blog.symbiotic-development.com/2008/02/10/ddd-and-nhibernate/</link>
		<comments>http://blog.symbiotic-development.com/2008/02/10/ddd-and-nhibernate/#comments</comments>
		<pubDate>Sat, 09 Feb 2008 23:35:34 +0000</pubDate>
		<dc:creator>Symon Rottem</dc:creator>
				<category><![CDATA[DDD]]></category>
		<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[ORM]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://symbiotic-development.com/blog/2008/02/10/ddd-and-nhibernate/</guid>
		<description><![CDATA[I was trawling around the net today and stumbled over a series of posts (some of which are now quite old) by Ben Scheirman about developing applications using DDD with NHibernate. I don&#8217;t recall having seen this series when I was starting to get my head around both of these concepts and they would have [...]]]></description>
			<content:encoded><![CDATA[<p>I was trawling around the net today and stumbled over a series of posts (some of which are now quite old)  by <a href="http://www.flux88.com/" target="_blank">Ben Scheirman</a> about developing applications using DDD with NHibernate.  I don&#8217;t recall having seen this series when I was starting to get my head around both of these concepts and they would have been invaluable at the time so I thought it would be worth re-posting the links to the posts for posterity&#8217;s sake and for those developers out there who are just getting started.</p>
<p>The series was (after having the name refactored a couple of times) called <em><strong>A Journey with Domain Driven Design (and NHibernate).  </strong></em>In the series Ben manages manages to cover a few design patterns, some TDD concepts and examples, separation of concerns, configuring NHibernate, writing mapping files and pulling it all together.</p>
<p>Following are the links to the articles and a quick overview of what each part covers:</p>
<ul>
<li><a href="http://www.flux88.com/AJourneyWithNHibernatePart1.aspx" target="_blank">Part 1</a> &#8211; Describes the reasoning behind his approach and the project structure used in the series.</li>
<li><a href="http://www.flux88.com/AJourneyWithNHibernatePart2.aspx">Part 2</a> &#8211; Covers the application and its requirements and begins designing the domain model.</li>
<li><a href="http://www.flux88.com/AJourneyWithNHibernateAndDDDPart3.aspx">Part 3</a> &#8211; Demonstrates writing basic unit tests for the domain model.</li>
<li><a href="http://www.flux88.com/AJourneyWithDomainDrivenDesignAndNHibernatePart4.aspx">Part 4</a> &#8211; Demonstrates more sophisticated tests that include interactions between domain entities.</li>
<li><a href="http://www.flux88.com/AJourneyWithDomainDrivenDesignAndNHibernatePart5.aspx">Part 5</a> &#8211; Database design strategies, configuring NHibernate and starts unit testing the persistence assembly .</li>
<li><a href="http://www.flux88.com/2006/09/02/A+Journey+With+Domain+Driven+Design+And+NHibernate++Part+6.aspx">Part 6</a> &#8211; NHibernate class and component mappings and some tests to check they&#8217;re working as expected.</li>
<li><a href="http://www.flux88.com/AJourneyWithDomainDrivenDesignAndNHibernatePart7.aspx">Part 7</a> &#8211; NHibernate collection and association mapping.</li>
<li><a href="http://www.flux88.com/AJourneyWithDomainDrivenDesignAndNHibernatePart8.aspx">Part 8</a> &#8211; Some refactoring, the introduction to use of the Repository pattern and use of the Template Method design pattern.</li>
<li><a href="http://www.flux88.com/AJourneyWithDomainDrivenDesignAndNHibernatePart9.aspx">Part 9</a> &#8211; Wrapping up the feature list and a link to download the latest version of the code.</li>
</ul>
<p>The series is excellent and recommended reading if you are trying to get off the ground with DDD and NHibernate.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.symbiotic-development.com/2008/02/10/ddd-and-nhibernate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Configuring NHibernate Caches</title>
		<link>http://blog.symbiotic-development.com/2008/02/09/configuring-nhibernate-caches/</link>
		<comments>http://blog.symbiotic-development.com/2008/02/09/configuring-nhibernate-caches/#comments</comments>
		<pubDate>Sat, 09 Feb 2008 14:05:29 +0000</pubDate>
		<dc:creator>Symon Rottem</dc:creator>
				<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[ORM]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[second-level]]></category>
		<category><![CDATA[SysCache]]></category>

		<guid isPermaLink="false">http://symbiotic-development.com/blog/2008/02/09/configuring-nhibernate-caches/</guid>
		<description><![CDATA[A little while ago I decided it would be prudent to start using the second level cache in NHibernate to improve performance in a couple of web applications my team and I had written. The database was taking quite a bit of punishment and performance was degrading while the data being queried was often fairly [...]]]></description>
			<content:encoded><![CDATA[<p>A little while ago I decided it would be prudent to start using the second level cache in NHibernate to improve performance in a couple of web applications my team and I had written.  The database was taking quite a bit of punishment and performance was degrading while the data being queried was often fairly static in nature so caching seemed like the right choice.</p>
<p>I&#8217;d seen some samples out there where people had added the cache configuration directives in their .hbm files so off I went and started adding the &lt;cache&gt; element to my class and collection mappings, configured the SysCache provider in my configuration file and <em>voila</em>, we were off and running with the first application.  Then I sat down and started thinking&#8230;</p>
<p>Now you are probably asking yourself the same question I was &#8211; why didn&#8217;t I sit down and think <em>first</em>?  An excellent question &#8211; one I&#8217;ll sit down and think about. Hmmm.</p>
<p>The problem was that the applications in question share the same domain model assembly, which in turn share the same NHibernate mapping files but each application has <em>it&#8217;s own caching requirements</em> so I couldn&#8217;t reuse the new cache settings between applications.  For one application we don&#8217;t intend to ever write values to a particular class so they could be mapped to the cache as read-only, while in another application the cached value for the same class should be read-write.  Since we were looking at using caching for performance reasons it certainly seemed to make sense that we use the cache in the most performant way possible.</p>
<p>After doing a bit of extra reading of the NHibernate docs I realized that you don&#8217;t have to add you cache directives to your mapping classes; there&#8217;s a single line in the documentation I had missed:</p>
<blockquote><p>Alternatively (preferrably?), you may specify <tt class="literal">&lt;class-cache&gt;</tt> and                  <tt class="literal">&lt;collection-cache&gt;</tt> elements in <tt class="literal">hibernate.cfg.xml</tt>.</p></blockquote>
<p>I guess the lesson here is read the documentation more carefully&#8230;</p>
<p>So, after adding the class and collection cache mappings to our NHibernate configuration we also added some cache regions with appropriate expiry periods for each application and turned on the query cache and started up the applications again.  The performance difference is quite something &#8211; the database load, which was moderately heavy, dropped significantly and the response times for the applications in question suddenly jumped.  I never did do any real comparison measurements but the difference was significant enough.</p>
<p>I have noticed, however, that when using the SysCache provider and setting expiration that sometimes the objects aren&#8217;t expired from the cache as promptly as I would have expected.  I haven&#8217;t yet investigated this issue in depth, but it&#8217;s nagging at me.  I&#8217;ll report back when I have more concrete data, but if there&#8217;s anyone out there who can shed some light I&#8217;d be glad for some feedback.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.symbiotic-development.com/2008/02/09/configuring-nhibernate-caches/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
