<?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: Implementing A Value Object With NHibernate</title> <atom:link href="http://davybrion.com/blog/2009/03/implementing-a-value-object-with-nhibernate/feed/" rel="self" type="application/rss+xml" /><link>http://davybrion.com/blog/2009/03/implementing-a-value-object-with-nhibernate/</link> <description>inquisitive: adjective. given to inquiry, research, or asking questions; eager for knowledge; intellectually curious</description> <lastBuildDate>Sun, 20 May 2012 21:55:00 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.2</generator> <item><title>By: Davy Brion</title><link>http://davybrion.com/blog/2009/03/implementing-a-value-object-with-nhibernate/comment-page-1/#comment-22646</link> <dc:creator>Davy Brion</dc:creator> <pubDate>Sun, 04 Oct 2009 16:17:45 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=1174#comment-22646</guid> <description>@Jeffhope this answers your question:
http://davybrion.com/blog/2009/10/why-nhibernate-entities-need-a-public-or-protected-parameterless-constructor/</description> <content:encoded><![CDATA[<p>@Jeff</p><p>hope this answers your question:<br
/> <a
href="http://davybrion.com/blog/2009/10/why-nhibernate-entities-need-a-public-or-protected-parameterless-constructor/" rel="nofollow">http://davybrion.com/blog/2009/10/why-nhibernate-entities-need-a-public-or-protected-parameterless-constructor/</a></p> ]]></content:encoded> </item> <item><title>By: Jeff</title><link>http://davybrion.com/blog/2009/03/implementing-a-value-object-with-nhibernate/comment-page-1/#comment-22644</link> <dc:creator>Jeff</dc:creator> <pubDate>Sun, 04 Oct 2009 13:49:55 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=1174#comment-22644</guid> <description>Could you elaborate on this?&lt;blockquote&gt;NHibernate allows a private default constructor for Value Objects, but for Entities you will need a default public or protected constructor as private is not sufficient.&lt;blockquote&gt;I too am trying to determine how well NHibernate lives up to the promise of persistence ignorance. I can definitely live with unnecessary private constructors, but I&#039;m dubious about adding protected constructors just to support an ORM.At any rate, I was surprised by the sentence I quoted, because I didn&#039;t realize there were any circumstances in which NHibernate required protected default constructors.</description> <content:encoded><![CDATA[<p>Could you elaborate on this?</p><blockquote><p>NHibernate allows a private default constructor for Value Objects, but for Entities you will need a default public or protected constructor as private is not sufficient.<br
/><blockquote><p>I too am trying to determine how well NHibernate lives up to the promise of persistence ignorance. I can definitely live with unnecessary private constructors, but I&#8217;m dubious about adding protected constructors just to support an ORM.</p><p>At any rate, I was surprised by the sentence I quoted, because I didn&#8217;t realize there were any circumstances in which NHibernate required protected default constructors.</p></blockquote></blockquote> ]]></content:encoded> </item> <item><title>By: Billy Stack</title><link>http://davybrion.com/blog/2009/03/implementing-a-value-object-with-nhibernate/comment-page-1/#comment-11116</link> <dc:creator>Billy Stack</dc:creator> <pubDate>Fri, 03 Apr 2009 08:04:56 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=1174#comment-11116</guid> <description>I must look into the using the Tuplizer approach!BTW I am a major supporter of NHibernate. IMO its definitely the best ORM available for the technologies I use. I also aspire to write software using DDD methods so Im just trying my best to marry the two (NHibernate + DDD that is!)Cheers</description> <content:encoded><![CDATA[<p>I must look into the using the Tuplizer approach!</p><p>BTW I am a major supporter of NHibernate. IMO its definitely the best ORM available for the technologies I use. I also aspire to write software using DDD methods so Im just trying my best to marry the two (NHibernate + DDD that is!)</p><p>Cheers</p> ]]></content:encoded> </item> <item><title>By: Davy Brion</title><link>http://davybrion.com/blog/2009/03/implementing-a-value-object-with-nhibernate/comment-page-1/#comment-11073</link> <dc:creator>Davy Brion</dc:creator> <pubDate>Thu, 02 Apr 2009 19:46:09 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=1174#comment-11073</guid> <description>yeah, it&#039;s a discussion that will probably keep going for a while ;)&quot;In my opinion, you cannot just assume that the database is correct. In 99% of applications concerning a database - some manual maintenance interaction with the database is required and just because the code guarentees value object validity when saved, you cannot assume the value object is correct.&quot;i really think that depends on application to application.  In some cases, you will be able to depend on it, in some you won&#039;t. 99% is definitely pushing it a little bit too far, i think ;)in those cases where you do control the database completely, i think a private default constructor with a custom constructor which does validity checks is sufficient.  If you don&#039;t control the database completely, then the Tuplizer approach might solve some of your problems.  But in that situation, you&#039;ll probably have more things to worry about than just the validity of value objects ;)</description> <content:encoded><![CDATA[<p>yeah, it&#8217;s a discussion that will probably keep going for a while <img
src='http://d18sni7re4ly7f.cloudfront.net/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p><p>&#8220;In my opinion, you cannot just assume that the database is correct. In 99% of applications concerning a database &#8211; some manual maintenance interaction with the database is required and just because the code guarentees value object validity when saved, you cannot assume the value object is correct.&#8221;</p><p>i really think that depends on application to application.  In some cases, you will be able to depend on it, in some you won&#8217;t. 99% is definitely pushing it a little bit too far, i think <img
src='http://d18sni7re4ly7f.cloudfront.net/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p><p>in those cases where you do control the database completely, i think a private default constructor with a custom constructor which does validity checks is sufficient.  If you don&#8217;t control the database completely, then the Tuplizer approach might solve some of your problems.  But in that situation, you&#8217;ll probably have more things to worry about than just the validity of value objects <img
src='http://d18sni7re4ly7f.cloudfront.net/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p> ]]></content:encoded> </item> <item><title>By: Billy Stack</title><link>http://davybrion.com/blog/2009/03/implementing-a-value-object-with-nhibernate/comment-page-1/#comment-11055</link> <dc:creator>Billy Stack</dc:creator> <pubDate>Thu, 02 Apr 2009 15:44:30 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=1174#comment-11055</guid> <description>There was a discussion/debate about this (quite a few times actually) on the NHibernate forums and DDD forum.In my opinion, you cannot just assume that the database is correct. In 99% of applications concerning a database - some manual maintenance interaction with the database is required and just because the code guarentees value object validity when saved, you cannot assume the value object is correct.A value type should always be in a valid state - Not validating that the type being read from the database is valid means you cannot stand over your applications value types being in a valid state!We got around this by using PostLoadEventListener - where ctor with guard clauses is called.</description> <content:encoded><![CDATA[<p>There was a discussion/debate about this (quite a few times actually) on the NHibernate forums and DDD forum.</p><p>In my opinion, you cannot just assume that the database is correct. In 99% of applications concerning a database &#8211; some manual maintenance interaction with the database is required and just because the code guarentees value object validity when saved, you cannot assume the value object is correct.</p><p>A value type should always be in a valid state &#8211; Not validating that the type being read from the database is valid means you cannot stand over your applications value types being in a valid state!</p><p>We got around this by using PostLoadEventListener &#8211; where ctor with guard clauses is called.</p> ]]></content:encoded> </item> <item><title>By: Davy Brion</title><link>http://davybrion.com/blog/2009/03/implementing-a-value-object-with-nhibernate/comment-page-1/#comment-11052</link> <dc:creator>Davy Brion</dc:creator> <pubDate>Thu, 02 Apr 2009 15:11:58 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=1174#comment-11052</guid> <description>btw, if your application is the only thing that&#039;s touching your database, then you could argue that value objects that are retrieved from the database (and need to be created with the default constructor by NH) should _always_ be in a valid state.  If that is not the case, your own code allowed persistence of an invalid value object somewhere, which would definitely be a problem in your code.So, if your code can guarantee that no invalid value objects are persisted, then you can still perform all the necessary guard checks in your own constructor, which would be the only one your code can use (since the default constructor would be private) and then you&#039;d never have invalid value objects.</description> <content:encoded><![CDATA[<p>btw, if your application is the only thing that&#8217;s touching your database, then you could argue that value objects that are retrieved from the database (and need to be created with the default constructor by NH) should _always_ be in a valid state.  If that is not the case, your own code allowed persistence of an invalid value object somewhere, which would definitely be a problem in your code.</p><p>So, if your code can guarantee that no invalid value objects are persisted, then you can still perform all the necessary guard checks in your own constructor, which would be the only one your code can use (since the default constructor would be private) and then you&#8217;d never have invalid value objects.</p> ]]></content:encoded> </item> <item><title>By: Davy Brion</title><link>http://davybrion.com/blog/2009/03/implementing-a-value-object-with-nhibernate/comment-page-1/#comment-11051</link> <dc:creator>Davy Brion</dc:creator> <pubDate>Thu, 02 Apr 2009 14:55:39 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=1174#comment-11051</guid> <description>@Billyi believe you can avoid the need for a default constructor by using a Tuplizer, but i can&#039;t immediately find a good link on thatabout the validation... i guess it depends, if you need to validate each property on its own, you could tell nhibernate to map against private setters in the value type instead of private fields.  In that case, the setters could perform some kind of basic evaluation.  If you need to validate them together, then you&#039;ll either need a custom validation method or you might get it done using the Tuplizer solution.I agree that NH doesn&#039;t offer 100% persistence ignorance... but i do think it&#039;s about as close as you&#039;ll come outside of rolling your own</description> <content:encoded><![CDATA[<p>@Billy</p><p>i believe you can avoid the need for a default constructor by using a Tuplizer, but i can&#8217;t immediately find a good link on that</p><p>about the validation&#8230; i guess it depends, if you need to validate each property on its own, you could tell nhibernate to map against private setters in the value type instead of private fields.  In that case, the setters could perform some kind of basic evaluation.  If you need to validate them together, then you&#8217;ll either need a custom validation method or you might get it done using the Tuplizer solution.</p><p>I agree that NH doesn&#8217;t offer 100% persistence ignorance&#8230; but i do think it&#8217;s about as close as you&#8217;ll come outside of rolling your own</p> ]]></content:encoded> </item> <item><title>By: Billy Stack</title><link>http://davybrion.com/blog/2009/03/implementing-a-value-object-with-nhibernate/comment-page-1/#comment-11027</link> <dc:creator>Billy Stack</dc:creator> <pubDate>Thu, 02 Apr 2009 07:38:06 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=1174#comment-11027</guid> <description>Davy,I have spent a good amount of time researching the use of &quot;immutable types&quot; with NHibernate see http://forum.hibernate.org/viewtopic.php?p=2392717
http://unhandled-exceptions.com/blog/index.php/2008/08/04/summer-of-nhibernate-session-07-exploring-mn-relationships-views-and-components/ (see comment at end)In my opinion NHibernate + true DDD dont really fit easily!You mention that there is a workaround to not use the default constructor. Can you elaborate a little more on this? In my opinion, in a DDD world, the domain must be completely persistence ignorant - the default constructor breaks that!Also, we strive to ensure that all value types are in a valid state so we validate our type by performing guard checks in the ctor(within the ctor which takes in the args!). Do you not validate your value types?This becomes even more problematic when you are retrieving a value type from the database - NHibernate instantiates the type using default ctor and sets the types properties through reflection. At the moment we use a PostLoadEventListener implementation where the constructor that has arguments is called instead. If one of the guard checks fail we throw an exception.</description> <content:encoded><![CDATA[<p>Davy,</p><p>I have spent a good amount of time researching the use of &#8220;immutable types&#8221; with NHibernate see <a
href="http://forum.hibernate.org/viewtopic.php?p=2392717" rel="nofollow">http://forum.hibernate.org/viewtopic.php?p=2392717</a><br
/> <a
href="http://unhandled-exceptions.com/blog/index.php/2008/08/04/summer-of-nhibernate-session-07-exploring-mn-relationships-views-and-components/" rel="nofollow">http://unhandled-exceptions.com/blog/index.php/2008/08/04/summer-of-nhibernate-session-07-exploring-mn-relationships-views-and-components/</a> (see comment at end)</p><p>In my opinion NHibernate + true DDD dont really fit easily!</p><p>You mention that there is a workaround to not use the default constructor. Can you elaborate a little more on this? In my opinion, in a DDD world, the domain must be completely persistence ignorant &#8211; the default constructor breaks that!</p><p>Also, we strive to ensure that all value types are in a valid state so we validate our type by performing guard checks in the ctor(within the ctor which takes in the args!). Do you not validate your value types?</p><p>This becomes even more problematic when you are retrieving a value type from the database &#8211; NHibernate instantiates the type using default ctor and sets the types properties through reflection. At the moment we use a PostLoadEventListener implementation where the constructor that has arguments is called instead. If one of the guard checks fail we throw an exception.</p> ]]></content:encoded> </item> <item><title>By: Davy Brion</title><link>http://davybrion.com/blog/2009/03/implementing-a-value-object-with-nhibernate/comment-page-1/#comment-10555</link> <dc:creator>Davy Brion</dc:creator> <pubDate>Thu, 26 Mar 2009 09:24:00 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=1174#comment-10555</guid> <description>@Mattthat&#039;s a nice approach... the default Equality and GetHashCode implementations will probably be good enough for most cases, and for those where you need better performance of Equals and GetHashCode, you can still provide an overridden optimized implementation.</description> <content:encoded><![CDATA[<p>@Matt</p><p>that&#8217;s a nice approach&#8230; the default Equality and GetHashCode implementations will probably be good enough for most cases, and for those where you need better performance of Equals and GetHashCode, you can still provide an overridden optimized implementation.</p> ]]></content:encoded> </item> <item><title>By: Matt Hinze</title><link>http://davybrion.com/blog/2009/03/implementing-a-value-object-with-nhibernate/comment-page-1/#comment-10554</link> <dc:creator>Matt Hinze</dc:creator> <pubDate>Thu, 26 Mar 2009 09:19:13 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=1174#comment-10554</guid> <description>Or you can use a base class like http://grabbagoft.blogspot.com/2007/06/generic-value-object-equality.html</description> <content:encoded><![CDATA[<p>Or you can use a base class like <a
href="http://grabbagoft.blogspot.com/2007/06/generic-value-object-equality.html" rel="nofollow">http://grabbagoft.blogspot.com/2007/06/generic-value-object-equality.html</a></p> ]]></content:encoded> </item> <item><title>By: Reflective Perspective - Chris Alcock &#187; The Morning Brew #315</title><link>http://davybrion.com/blog/2009/03/implementing-a-value-object-with-nhibernate/comment-page-1/#comment-10550</link> <dc:creator>Reflective Perspective - Chris Alcock &#187; The Morning Brew #315</dc:creator> <pubDate>Thu, 26 Mar 2009 08:37:00 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=1174#comment-10550</guid> <description>[...] Implementing A Value Object With NHibernate - Davy Brion looks at the specifics of implementing value objects when using NHibernate as your persistence framework [...]</description> <content:encoded><![CDATA[<p>[...] Implementing A Value Object With NHibernate &#8211; Davy Brion looks at the specifics of implementing value objects when using NHibernate as your persistence framework [...]</p> ]]></content:encoded> </item> <item><title>By: LukeB</title><link>http://davybrion.com/blog/2009/03/implementing-a-value-object-with-nhibernate/comment-page-1/#comment-10534</link> <dc:creator>LukeB</dc:creator> <pubDate>Wed, 25 Mar 2009 22:32:17 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=1174#comment-10534</guid> <description>I have something similar for building a state-based workflow system except that I give my States an ID and map them to their own table. Workflow items have a State that maps to one of these &quot;pseudo-value&quot; objects.I&#039;m sure by doing that God killed a kitten somewhere, but it&#039;s worked out well and is slightly more normalized than mapping as Components.</description> <content:encoded><![CDATA[<p>I have something similar for building a state-based workflow system except that I give my States an ID and map them to their own table. Workflow items have a State that maps to one of these &#8220;pseudo-value&#8221; objects.</p><p>I&#8217;m sure by doing that God killed a kitten somewhere, but it&#8217;s worked out well and is slightly more normalized than mapping as Components.</p> ]]></content:encoded> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 2/16 queries in 0.007 seconds using disk: basic
Object Caching 516/517 objects using disk: basic
Content Delivery Network via Amazon Web Services: CloudFront: d18sni7re4ly7f.cloudfront.net

Served from: davybrion.com @ 2012-05-22 11:17:31 -->
