<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Howdy, world</title>
	<atom:link href="http://sukita.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://sukita.wordpress.com</link>
	<description>Some tidbits on programming</description>
	<lastBuildDate>Sat, 10 Dec 2011 06:35:52 +0000</lastBuildDate>
	<language>th</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='sukita.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Howdy, world</title>
		<link>http://sukita.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://sukita.wordpress.com/osd.xml" title="Howdy, world" />
	<atom:link rel='hub' href='http://sukita.wordpress.com/?pushpress=hub'/>
		<item>
		<title>config.ru for Sinatra Applications</title>
		<link>http://sukita.wordpress.com/2011/12/10/config-ru-for-sinatra-applications/</link>
		<comments>http://sukita.wordpress.com/2011/12/10/config-ru-for-sinatra-applications/#comments</comments>
		<pubDate>Sat, 10 Dec 2011 06:35:48 +0000</pubDate>
		<dc:creator>sukita</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://sukita.wordpress.com/2011/12/10/config-ru-for-sinatra-applications/</guid>
		<description><![CDATA[Sinatra::Application class is a Rack objec, i.e. it responds_to? call(env). Per this documentation, it&#8217;s as easy as requiring your application file and run: #config.ru require './app'run Sinatra::Application<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sukita.wordpress.com&amp;blog=706710&amp;post=281&amp;subd=sukita&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Sinatra::Application class is a Rack objec, i.e. it responds_to? call(env).</p>
<p>Per this <a title="Using a Classic Style Application with a config.ru" href="http://www.sinatrarb.com/intro.html#Using%20a%20Classic%20Style%20Application%20with%20a%20config.ru">documentation</a>, it&#8217;s as easy as requiring your application file and run:</p>
<blockquote><pre>#config.ru
require './app'run Sinatra::Application</pre>
</blockquote>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sukita.wordpress.com/281/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sukita.wordpress.com/281/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sukita.wordpress.com/281/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sukita.wordpress.com/281/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sukita.wordpress.com/281/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sukita.wordpress.com/281/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sukita.wordpress.com/281/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sukita.wordpress.com/281/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sukita.wordpress.com/281/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sukita.wordpress.com/281/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sukita.wordpress.com/281/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sukita.wordpress.com/281/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sukita.wordpress.com/281/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sukita.wordpress.com/281/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sukita.wordpress.com&amp;blog=706710&amp;post=281&amp;subd=sukita&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sukita.wordpress.com/2011/12/10/config-ru-for-sinatra-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c3701cedfd1a927caf073cdf6600a6d1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Tik</media:title>
		</media:content>
	</item>
		<item>
		<title>Cascade Merge Entity in NHibernate</title>
		<link>http://sukita.wordpress.com/2010/09/13/cascade-merge-entity-in-nhibernate/</link>
		<comments>http://sukita.wordpress.com/2010/09/13/cascade-merge-entity-in-nhibernate/#comments</comments>
		<pubDate>Mon, 13 Sep 2010 15:33:25 +0000</pubDate>
		<dc:creator>sukita</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[nhibernate]]></category>

		<guid isPermaLink="false">http://sukita.wordpress.com/?p=195</guid>
		<description><![CDATA[Thou shall not forget to change thy configuration from cascade="save-update" to cascade="merge" when thou uses Session.Merge() to save thy object.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sukita.wordpress.com&amp;blog=706710&amp;post=195&amp;subd=sukita&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Thou shall not forget to change thy configuration from <code>cascade="save-update"</code> to <code>cascade="merge"</code> when thou uses Session.Merge() to save thy object.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sukita.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sukita.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sukita.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sukita.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sukita.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sukita.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sukita.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sukita.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sukita.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sukita.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sukita.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sukita.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sukita.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sukita.wordpress.com/195/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sukita.wordpress.com&amp;blog=706710&amp;post=195&amp;subd=sukita&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sukita.wordpress.com/2010/09/13/cascade-merge-entity-in-nhibernate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c3701cedfd1a927caf073cdf6600a6d1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Tik</media:title>
		</media:content>
	</item>
		<item>
		<title>Unable to find &#8216;Spring.Proxy&#8217; version 1.0.0.0</title>
		<link>http://sukita.wordpress.com/2010/08/31/unable-to-find-spring-proxy-version-1-0-0-0/</link>
		<comments>http://sukita.wordpress.com/2010/08/31/unable-to-find-spring-proxy-version-1-0-0-0/#comments</comments>
		<pubDate>Tue, 31 Aug 2010 04:11:36 +0000</pubDate>
		<dc:creator>sukita</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://sukita.wordpress.com/?p=192</guid>
		<description><![CDATA[If you get this error when calling Spring-based service hosted on IIS, and your service uses NHibernate for data access, and your service returns some objects that must be serialized&#8230;check your object graph. Make sure there is no NHibernate proxy in the object graph (i.e. do not use lazy loading).<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sukita.wordpress.com&amp;blog=706710&amp;post=192&amp;subd=sukita&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you get this error when calling Spring-based service hosted on IIS, and your service uses NHibernate for data access, and your service returns some objects that must be serialized&#8230;check your object graph.</p>
<p>Make sure there is no NHibernate proxy in the object graph (i.e. do not use lazy loading).</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sukita.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sukita.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sukita.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sukita.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sukita.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sukita.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sukita.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sukita.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sukita.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sukita.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sukita.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sukita.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sukita.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sukita.wordpress.com/192/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sukita.wordpress.com&amp;blog=706710&amp;post=192&amp;subd=sukita&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sukita.wordpress.com/2010/08/31/unable-to-find-spring-proxy-version-1-0-0-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c3701cedfd1a927caf073cdf6600a6d1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Tik</media:title>
		</media:content>
	</item>
		<item>
		<title>Include Null Properties in NHibernate QBE</title>
		<link>http://sukita.wordpress.com/2010/03/14/nhibernate-qbe-for-class-with-nullable-properties/</link>
		<comments>http://sukita.wordpress.com/2010/03/14/nhibernate-qbe-for-class-with-nullable-properties/#comments</comments>
		<pubDate>Sun, 14 Mar 2010 06:04:51 +0000</pubDate>
		<dc:creator>sukita</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[nhibernate]]></category>

		<guid isPermaLink="false">http://sukita.wordpress.com/?p=184</guid>
		<description><![CDATA[An easy way to include nullable properties in the query when using NHibernate's Query By Example (QBE) is to call <code>ExcludeNone</code> on your created example.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sukita.wordpress.com&amp;blog=706710&amp;post=184&amp;subd=sukita&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>To include properties with null values in NHibernate&#8217;s Query By Example (QBE), simply call <code>ExcludeNone()</code> on your created example.</p>
<p>For example, a class called ProductSize has 5 properties called Id, Dimension1, Dimension2, Dimension3, and Dimension4. All properties except Dimension1 are nullable. The combination of all dimension fields are unique for each record.</p>
<p>If I pass in an Example object with only Dimension1 set to 1, I want a search criteria like:</p>
<p><pre class="brush: sql;">
where Dimension1 = 1 and Dimension2 is null and Dimension3 is null and Dimension4 is null
</pre></p>
<p>NHibernate&#8217;s defaul behavior is to exclude all properties with null values when you create an Example object. So, this code would not work:</p>
<p><pre class="brush: csharp;">
var productSize = new ProductSize(1, 2, null, null);
var sampleSize = Example.Create(productSize);
var result = session.CreateCriteria&lt;ProductSize&gt;()
    .Add(sampleSize)
    .UniqueResult();
</pre></p>
<p>The generated SQL expression is</p>
<p><pre class="brush: sql;">
where Dimension1 = 1 and Dimension2 = 2
</pre></p>
<p>As a result, more than one record may be returned because the query does not include Dimension3 and Dimension4, and you&#8217;ll get an IncorrectResultSizeDataAccessException.</p>
<p>Here&#8217;s the code that works:</p>
<p><pre class="brush: csharp;">
var productSize = new ProductSize(1, 2, null, null);
var sampleSize = Example.Create(productSize).ExcludeNone();  // Include all properties.
var result = session.CreateCriteria&lt;ProductSize&gt;()
    .Add(sampleSize)
    .UniqueResult();
</pre></p>
<p>Using <code>ExcludeNone()</code> tells NHibernate to generate SQL expression based on all properties, including those will null values.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sukita.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sukita.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sukita.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sukita.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sukita.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sukita.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sukita.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sukita.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sukita.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sukita.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sukita.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sukita.wordpress.com/184/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sukita.wordpress.com/184/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sukita.wordpress.com/184/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sukita.wordpress.com&amp;blog=706710&amp;post=184&amp;subd=sukita&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sukita.wordpress.com/2010/03/14/nhibernate-qbe-for-class-with-nullable-properties/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c3701cedfd1a927caf073cdf6600a6d1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Tik</media:title>
		</media:content>
	</item>
		<item>
		<title>BindingSource xxxChanged Event Behavior</title>
		<link>http://sukita.wordpress.com/2010/03/08/bindingsource-xxxchanged-event-behavior/</link>
		<comments>http://sukita.wordpress.com/2010/03/08/bindingsource-xxxchanged-event-behavior/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 08:44:09 +0000</pubDate>
		<dc:creator>sukita</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://sukita.wordpress.com/?p=180</guid>
		<description><![CDATA[Some observations on the number of times CurrentChanged/PositionChanged/ListChanged event of .NET BindingSource is raised when we set its DataSource property to a DataTable.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sukita.wordpress.com&amp;blog=706710&amp;post=180&amp;subd=sukita&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Some observations on .NET BindingSource CurrentChanged/PositionChanged/ListChanged event behaviors. Here&#8217;s the code for producing the observations.</p>
<p><pre class="brush: csharp;">
private DataTable table = new DataTable();
private int i = 1;

private void Form1_Load(object sender, EventArgs e)
{
    // Hack: To prevent CurrentChanged from raising more than once, uncomment the line below.
    // bindingSource1.DataSource = table;

    table.Columns.Add(&quot;c1&quot;, typeof(string));
    for (int j = 0; j &lt; 5; j++)
    {
        var row = table.NewRow();
        row[&quot;c1&quot;] = &quot;row &quot; + i;
        i++;
        table.Rows.Add(row);
    }
    dataGridView1.DataSource = bindingSource1;
    bindingSource1.DataSource = table;
}
</pre></p>
<p>When we set DataSource for <code>bindingSource1</code>, CurrentChanged event is raised 3 times, ListChanged event twice, and PositionChanged event once.</p>
<p>When removing the last row, PositionChanged is raised twice (Position set to -1), while CurrentChanged and ListChanged are raised once per each event.</p>
<p>Clearing the table has the same effect has removing the last row.</p>
<p>Removing the first row (when there are more rows below) does not raise PositionChanged event because the Position stays the same. Only the selected value changes.</p>
<p>In summary:</p>
<ul>
<li>CurrentChanged works well in general, but we need to apply some hack to make sure the event is not raised many times on first initialization.</li>
<li>PositionChanged works well for initialization, but not for tracking addition, removal, or clearing. Use it if you only care about position, and be aware that clearing raises the event twice.</li>
<li>ListChanged&#8230;haven&#8217;t found a use case for it yet.
</ul>
<p><strong>Update (Mar 8, 2010)&#8230;</strong><br />
After playing with the code some more, a semi-automatic approach will hopefully keep me more sane while debugging in the long run. The idea is when setting the DataSource, use unsubscribe-resubscribe procedure as mentioned in this <a href="http://social.msdn.microsoft.com/forums/en-US/winformsdatacontrols/thread/5f968c71-a979-4e80-9896-94736e832f0c/">post</a>, then get the Current value manually. When adding, removing, clearing, selecting items, use CurrentChanged event as usual.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sukita.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sukita.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sukita.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sukita.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sukita.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sukita.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sukita.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sukita.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sukita.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sukita.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sukita.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sukita.wordpress.com/180/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sukita.wordpress.com/180/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sukita.wordpress.com/180/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sukita.wordpress.com&amp;blog=706710&amp;post=180&amp;subd=sukita&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sukita.wordpress.com/2010/03/08/bindingsource-xxxchanged-event-behavior/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c3701cedfd1a927caf073cdf6600a6d1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Tik</media:title>
		</media:content>
	</item>
		<item>
		<title>How To Test NHibernate Eager Loading with Spring Framework</title>
		<link>http://sukita.wordpress.com/2010/03/06/how-to-test-nhibernate-eager-loading-with-spring-framework/</link>
		<comments>http://sukita.wordpress.com/2010/03/06/how-to-test-nhibernate-eager-loading-with-spring-framework/#comments</comments>
		<pubDate>Sat, 06 Mar 2010 16:49:23 +0000</pubDate>
		<dc:creator>sukita</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[nhibernate]]></category>

		<guid isPermaLink="false">http://sukita.wordpress.com/?p=175</guid>
		<description><![CDATA[After spending a few nights trying to test NHibernate eager loading with Spring.NET framework&#8217;s AbstractTransactionalDbProviderSpringContextTests, I finally found the trick. First, clear the session (cache). Second, reload the object. Third, close the session. Finally, verify that the dependent object was loaded correctly and not proxied. The code below shows a test to check that the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sukita.wordpress.com&amp;blog=706710&amp;post=175&amp;subd=sukita&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>After spending a few nights trying to test NHibernate eager loading with Spring.NET framework&#8217;s <code>AbstractTransactionalDbProviderSpringContextTests</code>, I finally found the trick.</p>
<p>First, clear the session (cache). Second, reload the object. Third, close the session. Finally, verify that the dependent object was loaded correctly and not proxied.</p>
<p>The code below shows a test to check that the product type is loaded with a product.</p>
<p><pre class="brush: csharp;">
[Test]
public void GetProductShouldAlsoLoadProductType()
{
    var productType = productTypeRepository.Get(0);

    Product obj = new Product(&quot;A product&quot;, productType);

    productRepository.Store(obj);

    Flush();

    // Empty session cache. Clear all loaded objects.
    SessionFactory.GetCurrentSession().Clear();   // (1)

    var loaded = productRepository.Get(obj.Id); // (2)
    Assert.That(loaded, Is.Not.Null);

    // Close current session to make sure relevant objects are not proxied.
    EndTransaction();                                           // (3)

    Assert.That(NHibernateUtil.IsInitialized(loaded.ProductType), Is.True);
    Assert.That(loaded.ProductType.Name, Is.Not.Null.Or.Empty);
}
</pre></p>
<p>Note that the order of execution is important. You must clear the cache (1) before reloading the object (2) before closing the session (3) before testing your assertions.</p>
<p>If we do not clear the session cache in step (1), reloading the object (2) then closing the session (3) will still make the test pass. The reason is that even though the session is closed, the proxied object is there in the cache, literally meaning it has been loaded (and initialized). You can access the product type&#8217;s properties without any errors.</p>
<p>On the other hand, if you clear the session cache in step (1), loading the object in step (2) will create a proxy to <code>ProductType</code> class instead of a fully initialized object. When you close the session (3), the assertions will fail, and if you access any property of product type (besides its ID), you&#8217;ll get an exception saying the session has been closed.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sukita.wordpress.com/175/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sukita.wordpress.com/175/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sukita.wordpress.com/175/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sukita.wordpress.com/175/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sukita.wordpress.com/175/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sukita.wordpress.com/175/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sukita.wordpress.com/175/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sukita.wordpress.com/175/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sukita.wordpress.com/175/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sukita.wordpress.com/175/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sukita.wordpress.com/175/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sukita.wordpress.com/175/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sukita.wordpress.com/175/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sukita.wordpress.com/175/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sukita.wordpress.com&amp;blog=706710&amp;post=175&amp;subd=sukita&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sukita.wordpress.com/2010/03/06/how-to-test-nhibernate-eager-loading-with-spring-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c3701cedfd1a927caf073cdf6600a6d1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Tik</media:title>
		</media:content>
	</item>
		<item>
		<title>Strong-typed DataSet เป็นอันตรายสำหรับสถาปัตยกรรมระบบ</title>
		<link>http://sukita.wordpress.com/2010/01/29/strong-typed-dataset-considered-harmful/</link>
		<comments>http://sukita.wordpress.com/2010/01/29/strong-typed-dataset-considered-harmful/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 04:03:38 +0000</pubDate>
		<dc:creator>sukita</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://sukita.wordpress.com/?p=173</guid>
		<description><![CDATA[สำหรับใครก็ตามที่ต้องทำงานกับระบบที่มีขนาดย่อมขึ้นไปจนถึงใหญ่ ควรหลีกเลี่ยง strong-typed DataSet/DataAdapter ให้ไกลที่สุดเท่าที่จะเป็นไปได้ เพราะ strong-typed DataSet: ไม่เหมาะกับการสร้าง domain model ที่ดีเหมือน PONO และไม่ natural เพราะมันเป็นเหมือน container ขนาดใหญ่ที่ปนเรื่อง domain กับ persistence ไว้ด้วยกัน (DataTable ไม่ใช่ domain model) ความที่เป็น container ขนาดใหญ่ทำให้มีต้นทุนการ serialize/deserialize สุง (และจะยิ่งน่าเบื่อเมื่อ DataSet คุณมีประมาณ 100 table) ทั้งตอนพัฒนาด้วย designer และตอนใช้งานใน form (บางครั้งการสร้าง DataSet ขนาดใหญ่เพื่อที่จะใช้แค่ไม่กี่ตารางใช้เวลามากกว่าการ load form เสียอีก) ทำให้ต้องยึดติดกับ designer และ code generator ที่ทำงานช้า (สำหรับคนที่ไม่มีเครื่องแรง ๆ) ทำให้ขาดความยืดหยุ่นในการทำงานกับ database [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sukita.wordpress.com&amp;blog=706710&amp;post=173&amp;subd=sukita&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>สำหรับใครก็ตามที่ต้องทำงานกับระบบที่มีขนาดย่อมขึ้นไปจนถึงใหญ่ ควรหลีกเลี่ยง strong-typed DataSet/DataAdapter ให้ไกลที่สุดเท่าที่จะเป็นไปได้ เพราะ strong-typed DataSet:</p>
<ol>
<li>ไม่เหมาะกับการสร้าง domain model ที่ดีเหมือน PONO และไม่ natural เพราะมันเป็นเหมือน container ขนาดใหญ่ที่ปนเรื่อง domain กับ persistence ไว้ด้วยกัน (DataTable ไม่ใช่ domain model)</li>
<li>ความที่เป็น container ขนาดใหญ่ทำให้มีต้นทุนการ serialize/deserialize สุง (และจะยิ่งน่าเบื่อเมื่อ DataSet คุณมีประมาณ 100 table) ทั้งตอนพัฒนาด้วย designer และตอนใช้งานใน form (บางครั้งการสร้าง DataSet ขนาดใหญ่เพื่อที่จะใช้แค่ไม่กี่ตารางใช้เวลามากกว่าการ load form เสียอีก)</li>
<li>ทำให้ต้องยึดติดกับ designer และ code generator ที่ทำงานช้า (สำหรับคนที่ไม่มีเครื่องแรง ๆ)</li>
<li>ทำให้ขาดความยืดหยุ่นในการทำงานกับ database อื่น ๆ และยากที่จะ decouple เรื่อง persistence ออกมา ถ้าคุณต้องการเปลี่ยน DB คุณต้อง generate DataSet ใหม่ และไปแก้ไข compile error ที่อื่น ๆ อีกด้วย</li>
<li>ไม่เหมาะกับการทำงานใน application layer (service layer) เพราะ strong-typed TableAdapter ไม่มีอะไรที่ expose เรื่องการจัดการ transaction แบบ conversation (ถ้าใช้ TransactionScope อาจจะปวดหัวมากขึ้นกับปัญหาอื่น เช่นการ configure DTC เป็นต้น)</li>
</ol>
<p>สรุปได้ว่า การใช้ strong-typed DataSet เป็นศูนย์กลางของสถาปัตยกรรมระบบเพื่อแทน model และ data layer ทำให้ระบบขาดความยืดหยุ่นในระยะยาว</p>
<p>ถ้าคุณเปลี่ยน model เป็น PONO หลังจาก DataSet คุณมีประมาณ 100 ตาราง ก็แทบไม่ต่างอะไรกับการ rewrite ระบบใหม่ เพราะเปลี่ยน model ก็ต้องเปลี่ยนเรื่อง persistence และต้องเปลี่ยน UI อีกต่างหาก (ไม่ว่าจะเป็นการเรียกใช้ data layer หรือ data binding กับ model)</p>
<p>คำแนะนำ: หลีกเลี่ยง strong-typed DataSet หรือเปลี่ยนไปใช้สถาปัตยกรรมที่อิงกับ PONO ให้เร็วที่สุดก่อนที่ DataSet จะมีขนาดใหญ่เกินไป</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sukita.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sukita.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sukita.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sukita.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sukita.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sukita.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sukita.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sukita.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sukita.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sukita.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sukita.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sukita.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sukita.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sukita.wordpress.com/173/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sukita.wordpress.com&amp;blog=706710&amp;post=173&amp;subd=sukita&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sukita.wordpress.com/2010/01/29/strong-typed-dataset-considered-harmful/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c3701cedfd1a927caf073cdf6600a6d1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Tik</media:title>
		</media:content>
	</item>
		<item>
		<title>Spring: TypeInitializationException เวลาเรียก GetContext()</title>
		<link>http://sukita.wordpress.com/2010/01/01/spring-typeinitializationexception-%e0%b9%80%e0%b8%a7%e0%b8%a5%e0%b8%b2%e0%b9%80%e0%b8%a3%e0%b8%b5%e0%b8%a2%e0%b8%81-getcontext/</link>
		<comments>http://sukita.wordpress.com/2010/01/01/spring-typeinitializationexception-%e0%b9%80%e0%b8%a7%e0%b8%a5%e0%b8%b2%e0%b9%80%e0%b8%a3%e0%b8%b5%e0%b8%a2%e0%b8%81-getcontext/#comments</comments>
		<pubDate>Fri, 01 Jan 2010 09:38:30 +0000</pubDate>
		<dc:creator>sukita</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://sukita.wordpress.com/?p=166</guid>
		<description><![CDATA[If you use PropertyPlaceholderConfigurer and gets TypeInitializationException from Spring.NET when calling ContextRegistry.GetContext(), check that you have section handler for your placeholder section.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sukita.wordpress.com&amp;blog=706710&amp;post=166&amp;subd=sukita&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>ถ้าคุณเจอ TypeInitializationException แบบนี้เวลาเรียกใช้ ContextRegistry.GetContext():</p>
<p><pre class="brush: plain; light: true;">
An unhandled exception of type 'System.TypeInitializationException' occurred in WindowsApplication1.exe

Additional information: The type initializer for 'Spring.Context.Support.ContextRegistry' threw an exception.
</pre></p>
<p>ลองเช็คดูว่ามีการใช้ PropertyPlaceholderConfigurer หรือเปล่า? ถ้ามี ให้เพิ่ม handler สำหรับ section เข้าไปใน app.config ด้วย:</p>
<p><pre class="brush: xml;">
&lt;configSections&gt;
  ...
  &lt;section name=&quot;databaseSettings&quot;
           type=&quot;System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089&quot;/&gt;
&lt;/configSections&gt;
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sukita.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sukita.wordpress.com/166/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sukita.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sukita.wordpress.com/166/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sukita.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sukita.wordpress.com/166/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sukita.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sukita.wordpress.com/166/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sukita.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sukita.wordpress.com/166/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sukita.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sukita.wordpress.com/166/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sukita.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sukita.wordpress.com/166/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sukita.wordpress.com&amp;blog=706710&amp;post=166&amp;subd=sukita&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sukita.wordpress.com/2010/01/01/spring-typeinitializationexception-%e0%b9%80%e0%b8%a7%e0%b8%a5%e0%b8%b2%e0%b9%80%e0%b8%a3%e0%b8%b5%e0%b8%a2%e0%b8%81-getcontext/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c3701cedfd1a927caf073cdf6600a6d1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Tik</media:title>
		</media:content>
	</item>
		<item>
		<title>Spring.NET: ทำไมต้อง virtual สำหรับ method ที่มี [Transaction] attribute</title>
		<link>http://sukita.wordpress.com/2009/12/30/spring-net-transaction-methods-must-be-virtual-if-class-does-not-define-an-interface/</link>
		<comments>http://sukita.wordpress.com/2009/12/30/spring-net-transaction-methods-must-be-virtual-if-class-does-not-define-an-interface/#comments</comments>
		<pubDate>Wed, 30 Dec 2009 08:43:50 +0000</pubDate>
		<dc:creator>sukita</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://sukita.wordpress.com/?p=160</guid>
		<description><![CDATA[[Transaction] methods must be virtual if class does not define an interface.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sukita.wordpress.com&amp;blog=706710&amp;post=160&amp;subd=sukita&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>กรณีที่ class มี method ที่ใช้ [Transaction] attribute และ class นั้นไม่มี interface เราต้อง declare method นั้นเป็น virtual  เช่น</p>
<p><pre class="brush: csharp;">
// Class does not define an interface.
public class CustomerDao
{
  // We must declare this transactional method as virtual.
  [Transaction]
  public virtual void Save(Customer obj)
  {
    // Save to database.
  }
}
</pre></p>
<p>ที่จริงเราต้อง define ทุกๆ method และ property ที่ต้องการให้ Spring ใช้เป็น virtual ด้วยซ้ำ เพราะว่า Spring สร้าง class proxy โดยการสร้างอีก class นึงที่ inherit มาจาก CustomerDao และ override ทุก public method/property ที่สามารถ override ได้ (Decorator pattern) เพื่อเพิ่ม advice เข้าไป  ส่วน method ที่ไม่ใช่ virtual ไม่สามารถถูก override ได้ เพราะฉะนั้น Spring ก็จะไม่ยุ่งอะไรกับ method พวกนี้</p>
<p>[Transaction] attribute ไม่สามารถทำงานได้กับ method ที่ไม่มี virtual เพราะ Spring ไม่สามารถเพิ่ม transaction advice ครอบ method นั้นๆ ได้</p>
<p>ลองอ่านเพิ่มเติมได้ที่หัวข้อ <a href="http://www.springframework.net/doc-latest/reference/html/aop.html#d4e4209">13.5.4 Proxying Classes</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sukita.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sukita.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sukita.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sukita.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sukita.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sukita.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sukita.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sukita.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sukita.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sukita.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sukita.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sukita.wordpress.com/160/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sukita.wordpress.com/160/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sukita.wordpress.com/160/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sukita.wordpress.com&amp;blog=706710&amp;post=160&amp;subd=sukita&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sukita.wordpress.com/2009/12/30/spring-net-transaction-methods-must-be-virtual-if-class-does-not-define-an-interface/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c3701cedfd1a927caf073cdf6600a6d1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Tik</media:title>
		</media:content>
	</item>
		<item>
		<title>Spring.NET : NullReferenceException เวลาใช้ field ของ dependency พร้อมๆ กับ Transaction</title>
		<link>http://sukita.wordpress.com/2009/12/30/spring-net-nullreferenceexception-%e0%b9%80%e0%b8%a7%e0%b8%a5%e0%b8%b2%e0%b9%83%e0%b8%8a%e0%b9%89-field-%e0%b8%82%e0%b8%ad%e0%b8%87-dependency-%e0%b8%9e%e0%b8%a3%e0%b9%89%e0%b8%ad%e0%b8%a1%e0%b9%86/</link>
		<comments>http://sukita.wordpress.com/2009/12/30/spring-net-nullreferenceexception-%e0%b9%80%e0%b8%a7%e0%b8%a5%e0%b8%b2%e0%b9%83%e0%b8%8a%e0%b9%89-field-%e0%b8%82%e0%b8%ad%e0%b8%87-dependency-%e0%b8%9e%e0%b8%a3%e0%b9%89%e0%b8%ad%e0%b8%a1%e0%b9%86/#comments</comments>
		<pubDate>Wed, 30 Dec 2009 07:17:43 +0000</pubDate>
		<dc:creator>sukita</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://sukita.wordpress.com/?p=155</guid>
		<description><![CDATA[สมมุติว่าเราตั้งค่า object อันนึงใน Spring.NET ชื่อ dataService ซึ่งใช้อีก object นึงชื่อ adoTemplate ทั้งสอง object ถูกตั้งค่าไว้แล้ว DataService เป็น class ใน service layer ธรรมดา ไม่มี interface ไม่มี base class อะไร โค้ดด้านบนเป็นโค้ดที่ผิด เพราะสองสาเหตุ สาเหตุแรกคือ เราไม่ได้ใช้ property AdoTemplate แต่ใช้ field ที่ชื่อ adoTemplate ใน MyMethod ที่ถูกแล้วเราควรใช้ property เพราะฟิลด์นี้อาจไม่ถูก set ค่าเวลา Spring สร้าง proxy ผลที่เกิดก็คือเราจะเจอ NullReferenceException เวลาถึงบรรทัด adoTemplate.Execute(&#8230;) ข้อที่สองคือ เราไม่ได้ประกาศ AdoTemplate เป็น virtual [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sukita.wordpress.com&amp;blog=706710&amp;post=155&amp;subd=sukita&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>สมมุติว่าเราตั้งค่า object อันนึงใน Spring.NET ชื่อ dataService ซึ่งใช้อีก object นึงชื่อ adoTemplate  ทั้งสอง object ถูกตั้งค่าไว้แล้ว</p>
<p><pre class="brush: xml;">
&lt;object id=&quot;adoTemplate&quot; type=&quot;Spring.Data.Core.AdoTemplate, Spring.Data&quot;&gt;
  &lt;property name=&quot;DbProvider&quot; ref=&quot;dbProvider&quot;/&gt;
&lt;/object&gt;
&lt;object id=&quot;dataService&quot; type=&quot;MyApp.DataService, MyApp&quot;&gt;
  &lt;property name=&quot;AdoTemplate&quot; ref=&quot;adoTemplate&quot;/&gt;
&lt;/object&gt;
</pre></p>
<p>DataService เป็น class ใน service layer ธรรมดา ไม่มี interface ไม่มี base class อะไร</p>
<p><pre class="brush: csharp;">
[Service]
public class DataService
{
  private AdoTemplate adoTemplate;
  
  public AdoTemplate AdoTemplate
  {
    set { adoTemplate = value; }
  }

  [Transaction]
  public void MyMethod()
  {
    // This code does not work.
    this.adoTemplate.Execute(...);
    this.adoTemplate.Execute(...);
  }
}
</pre></p>
<p>โค้ดด้านบนเป็นโค้ดที่ผิด เพราะสองสาเหตุ</p>
<p>สาเหตุแรกคือ เราไม่ได้ใช้ property AdoTemplate แต่ใช้ field ที่ชื่อ adoTemplate ใน MyMethod  ที่ถูกแล้วเราควรใช้ property  เพราะฟิลด์นี้อาจไม่ถูก set ค่าเวลา Spring สร้าง proxy  ผลที่เกิดก็คือเราจะเจอ NullReferenceException เวลาถึงบรรทัด adoTemplate.Execute(&#8230;)</p>
<p>ข้อที่สองคือ เราไม่ได้ประกาศ AdoTemplate เป็น virtual ทำให้ Spring ไม่ได้ set ค่าของ AdoTemplate property เวลาสร้าง context</p>
<p>สรุปแล้ว โค้ดที่ถูกต้องคือ</p>
<p><pre class="brush: csharp;">
[Service]
public class DataService
{
  private AdoTemplate adoTemplate;
  
  // Don't forget to make this virtual.
  public virtual AdoTemplate AdoTemplate
  {
    set { adoTemplate = value; }
  }

  [Transaction]
  public void MyMethod()
  {
    // Use property instead of field.
    AdoTemplate.Execute(...);
    AdoTemplate.Execute(...);
  }
}
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sukita.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sukita.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sukita.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sukita.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/sukita.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/sukita.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/sukita.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/sukita.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sukita.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sukita.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sukita.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sukita.wordpress.com/155/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sukita.wordpress.com/155/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sukita.wordpress.com/155/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sukita.wordpress.com&amp;blog=706710&amp;post=155&amp;subd=sukita&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://sukita.wordpress.com/2009/12/30/spring-net-nullreferenceexception-%e0%b9%80%e0%b8%a7%e0%b8%a5%e0%b8%b2%e0%b9%83%e0%b8%8a%e0%b9%89-field-%e0%b8%82%e0%b8%ad%e0%b8%87-dependency-%e0%b8%9e%e0%b8%a3%e0%b9%89%e0%b8%ad%e0%b8%a1%e0%b9%86/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c3701cedfd1a927caf073cdf6600a6d1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Tik</media:title>
		</media:content>
	</item>
	</channel>
</rss>
