<?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: I don&#8217;t believe in ORM object as your domain model</title>
	<atom:link href="http://sarahtaraporewalla.com/thoughts/design/i-dont-believe-in-orm-object-as-your-domain-model/feed/" rel="self" type="application/rss+xml" />
	<link>http://sarahtaraporewalla.com/thoughts/design/i-dont-believe-in-orm-object-as-your-domain-model/</link>
	<description></description>
	<lastBuildDate>Mon, 01 Feb 2010 18:01:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Torbjörn Gyllebring</title>
		<link>http://sarahtaraporewalla.com/thoughts/design/i-dont-believe-in-orm-object-as-your-domain-model/comment-page-1/#comment-2991</link>
		<dc:creator>Torbjörn Gyllebring</dc:creator>
		<pubDate>Fri, 05 Jun 2009 06:40:35 +0000</pubDate>
		<guid isPermaLink="false">http://sarahtaraporewalla.com/thoughts/?p=204#comment-2991</guid>
		<description>Great post! Conceptually I like to talk about and think about the following models:
Persistance, Domain, and Presentation Model. 
Now for any given application we&#039;re moving along a continium where at one end we have &quot;The database on screen&quot; basically how webapplciations been built for the last 15or so years and in many respects Rails seems to be the absolute peak of such frameworks, and it does work for many applications. On the other side we end up with all three models clearly visible in the design forced to crystalize because of the diffrent forces at work. The thins is that we always have theese, they just happen to align pretty perfectly with each other for a large class of applications. Experience teaches us to be mindfull of this and understand and know the source of our pains when we reach a point where conflicting needs start to pull them out of alignment and at that moment start pulling out new classes and concepts to ease that pain. Not knowing when todo so is just a big misstake as prematurly going for the 7layer cake mentioned earlier. 
As always, listen to the code and it will tell you how it wants to be.</description>
		<content:encoded><![CDATA[<p>Great post! Conceptually I like to talk about and think about the following models:<br />
Persistance, Domain, and Presentation Model.<br />
Now for any given application we&#8217;re moving along a continium where at one end we have &#8220;The database on screen&#8221; basically how webapplciations been built for the last 15or so years and in many respects Rails seems to be the absolute peak of such frameworks, and it does work for many applications. On the other side we end up with all three models clearly visible in the design forced to crystalize because of the diffrent forces at work. The thins is that we always have theese, they just happen to align pretty perfectly with each other for a large class of applications. Experience teaches us to be mindfull of this and understand and know the source of our pains when we reach a point where conflicting needs start to pull them out of alignment and at that moment start pulling out new classes and concepts to ease that pain. Not knowing when todo so is just a big misstake as prematurly going for the 7layer cake mentioned earlier.<br />
As always, listen to the code and it will tell you how it wants to be.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan Haywood</title>
		<link>http://sarahtaraporewalla.com/thoughts/design/i-dont-believe-in-orm-object-as-your-domain-model/comment-page-1/#comment-2987</link>
		<dc:creator>Dan Haywood</dc:creator>
		<pubDate>Thu, 04 Jun 2009 18:48:13 +0000</pubDate>
		<guid isPermaLink="false">http://sarahtaraporewalla.com/thoughts/?p=204#comment-2987</guid>
		<description>Another way of creating an &quot;ORM model&quot; - isn&#039;t it? - is to use good-ole fashioned views.

Initially the view is 1:1 with the underlying table.  As the two start to diverge, the view corresponds to the entity (the logical data model as we used to call it) and the table is, well, the physical data model.

Of course, historically views have been for read-only access or very limited update access.  But most RDBMS vendors (all the commercial ones) anyway, support INSTEAD OF triggers on views.

To my mind this seems like a much more natural place to put the abstraction layer (as and when you need it).  And it allows DBAs to easily do impact analysis when they want to change the physical database schema.

Cheers
Dan</description>
		<content:encoded><![CDATA[<p>Another way of creating an &#8220;ORM model&#8221; &#8211; isn&#8217;t it? &#8211; is to use good-ole fashioned views.</p>
<p>Initially the view is 1:1 with the underlying table.  As the two start to diverge, the view corresponds to the entity (the logical data model as we used to call it) and the table is, well, the physical data model.</p>
<p>Of course, historically views have been for read-only access or very limited update access.  But most RDBMS vendors (all the commercial ones) anyway, support INSTEAD OF triggers on views.</p>
<p>To my mind this seems like a much more natural place to put the abstraction layer (as and when you need it).  And it allows DBAs to easily do impact analysis when they want to change the physical database schema.</p>
<p>Cheers<br />
Dan</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sarah</title>
		<link>http://sarahtaraporewalla.com/thoughts/design/i-dont-believe-in-orm-object-as-your-domain-model/comment-page-1/#comment-2986</link>
		<dc:creator>Sarah</dc:creator>
		<pubDate>Thu, 04 Jun 2009 18:24:39 +0000</pubDate>
		<guid isPermaLink="false">http://sarahtaraporewalla.com/thoughts/?p=204#comment-2986</guid>
		<description>Thanks everyone for your comments, I will try to reply to your comments:

At the moment, I am buying into the concept that your domain model shouldn&#039;t know anything about other services - including how it is persisted. Exposing save, find etc operations on the models, as the ORMs do, breaks that concept.

You may have extra pain mapping between your domain and ORM models but just how much, I&#039;m not sure. 

@clinton - that sounds interesting...go straight for SQL. Then again, the ORM does make life easy to start with. Having said that, I find that often you usually need to tune your queries with ActiveRecord (rails) anyway.

@david - yes, that is a powerful thing, iff you a building a database-table-on-the-screen application. For anything more, you tend to start cursing AR (and sometimes DHH&#039;s attitude).

@toby - the way I see databases diverging from the model is in how you store the data. I am mainly referring to the times when you need to tune your database for performance reasons (putting indexes, normalizing your tables etc). 


@sai - the butterfly effect maybe?

(@ben - you know we basically had this on our last project).</description>
		<content:encoded><![CDATA[<p>Thanks everyone for your comments, I will try to reply to your comments:</p>
<p>At the moment, I am buying into the concept that your domain model shouldn&#8217;t know anything about other services &#8211; including how it is persisted. Exposing save, find etc operations on the models, as the ORMs do, breaks that concept.</p>
<p>You may have extra pain mapping between your domain and ORM models but just how much, I&#8217;m not sure. </p>
<p>@clinton &#8211; that sounds interesting&#8230;go straight for SQL. Then again, the ORM does make life easy to start with. Having said that, I find that often you usually need to tune your queries with ActiveRecord (rails) anyway.</p>
<p>@david &#8211; yes, that is a powerful thing, iff you a building a database-table-on-the-screen application. For anything more, you tend to start cursing AR (and sometimes DHH&#8217;s attitude).</p>
<p>@toby &#8211; the way I see databases diverging from the model is in how you store the data. I am mainly referring to the times when you need to tune your database for performance reasons (putting indexes, normalizing your tables etc). </p>
<p>@sai &#8211; the butterfly effect maybe?</p>
<p>(@ben &#8211; you know we basically had this on our last project).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben Butler-Cole</title>
		<link>http://sarahtaraporewalla.com/thoughts/design/i-dont-believe-in-orm-object-as-your-domain-model/comment-page-1/#comment-2982</link>
		<dc:creator>Ben Butler-Cole</dc:creator>
		<pubDate>Wed, 03 Jun 2009 21:58:51 +0000</pubDate>
		<guid isPermaLink="false">http://sarahtaraporewalla.com/thoughts/?p=204#comment-2982</guid>
		<description>I don&#039;t know. I just don&#039;t know. I can see that this is tempting. I&#039;d love to be able to treat persistence as just another view on the model (a la Alistair Cockburn&#039;s Hexagonal Architecture: http://alistair.cockburn.us/Hexagonal+architecture); and we often create view objects separate from the domain model. But isn&#039;t it just a bit more complicated than that? Doesn&#039;t the real world impinge?

How does your example deal with object graphs? You don&#039;t want to traverse the entire aggregate copying values just in case, do you? And can you do lazy loading?

I&#039;d love to know a real example of a problem that you are trying to solve with this solution that couldn&#039;t be solved by fancy mapping in Hibernate or even a special-case repository method that drops down to raw SQL.

You know what I really, really want? A framework that does all the fanch-shmancy stuff with object graph management and cleanliness tracking that a sophisticated ORM does, but just give me call-backs for dirty objects rather than persisting changes to a database. Then I really can have persistence as a view and ensure that all the views in my complex thick client get updated at the right time.

Ben</description>
		<content:encoded><![CDATA[<p>I don&#8217;t know. I just don&#8217;t know. I can see that this is tempting. I&#8217;d love to be able to treat persistence as just another view on the model (a la Alistair Cockburn&#8217;s Hexagonal Architecture: <a href="http://alistair.cockburn.us/Hexagonal+architecture)" rel="nofollow">http://alistair.cockburn.us/Hexagonal+architecture)</a>; and we often create view objects separate from the domain model. But isn&#8217;t it just a bit more complicated than that? Doesn&#8217;t the real world impinge?</p>
<p>How does your example deal with object graphs? You don&#8217;t want to traverse the entire aggregate copying values just in case, do you? And can you do lazy loading?</p>
<p>I&#8217;d love to know a real example of a problem that you are trying to solve with this solution that couldn&#8217;t be solved by fancy mapping in Hibernate or even a special-case repository method that drops down to raw SQL.</p>
<p>You know what I really, really want? A framework that does all the fanch-shmancy stuff with object graph management and cleanliness tracking that a sophisticated ORM does, but just give me call-backs for dirty objects rather than persisting changes to a database. Then I really can have persistence as a view and ensure that all the views in my complex thick client get updated at the right time.</p>
<p>Ben</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sai Venkat</title>
		<link>http://sarahtaraporewalla.com/thoughts/design/i-dont-believe-in-orm-object-as-your-domain-model/comment-page-1/#comment-2981</link>
		<dc:creator>Sai Venkat</dc:creator>
		<pubDate>Wed, 03 Jun 2009 19:09:27 +0000</pubDate>
		<guid isPermaLink="false">http://sarahtaraporewalla.com/thoughts/?p=204#comment-2981</guid>
		<description>I agree with you. I wrote something similar a few days back actually. http://sai-venkat.tumblr.com/post/101030289/activerecord-domain-model. 

P.S. It is odd and freaky that many TW people think alike. This experience is happening to me for the third time :)</description>
		<content:encoded><![CDATA[<p>I agree with you. I wrote something similar a few days back actually. <a href="http://sai-venkat.tumblr.com/post/101030289/activerecord-domain-model" rel="nofollow">http://sai-venkat.tumblr.com/post/101030289/activerecord-domain-model</a>. </p>
<p>P.S. It is odd and freaky that many TW people think alike. This experience is happening to me for the third time <img src='http://sarahtaraporewalla.com/thoughts/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Toby Tripp</title>
		<link>http://sarahtaraporewalla.com/thoughts/design/i-dont-believe-in-orm-object-as-your-domain-model/comment-page-1/#comment-2980</link>
		<dc:creator>Toby Tripp</dc:creator>
		<pubDate>Wed, 03 Jun 2009 19:01:21 +0000</pubDate>
		<guid isPermaLink="false">http://sarahtaraporewalla.com/thoughts/?p=204#comment-2980</guid>
		<description>Once I separate my ORM from my Model, the danger is I may now have to modify two classes whenever I want to add persistent data to my domain (three in your example!).  I&#039;m not okay with that.

The responsibility of what data resides in which model does not belong to my persistence code.  It belongs to my domain model, solely.

I also don&#039;t buy the idea that the database must eventually diverge from the domain model.  The only way I see that happening is when other applications integrate at the database layer, positively the worst place to do that sort of integration.

Work hard to keep your data model in line with your domain model.  Resist the temptation to let others put their grubby hands down your data pants.  Do that, and the motivation to keep DB Schema and Domain separate may fall away.


Thanks for the provocative entry, keep it up.

Toby</description>
		<content:encoded><![CDATA[<p>Once I separate my ORM from my Model, the danger is I may now have to modify two classes whenever I want to add persistent data to my domain (three in your example!).  I&#8217;m not okay with that.</p>
<p>The responsibility of what data resides in which model does not belong to my persistence code.  It belongs to my domain model, solely.</p>
<p>I also don&#8217;t buy the idea that the database must eventually diverge from the domain model.  The only way I see that happening is when other applications integrate at the database layer, positively the worst place to do that sort of integration.</p>
<p>Work hard to keep your data model in line with your domain model.  Resist the temptation to let others put their grubby hands down your data pants.  Do that, and the motivation to keep DB Schema and Domain separate may fall away.</p>
<p>Thanks for the provocative entry, keep it up.</p>
<p>Toby</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Moles</title>
		<link>http://sarahtaraporewalla.com/thoughts/design/i-dont-believe-in-orm-object-as-your-domain-model/comment-page-1/#comment-2970</link>
		<dc:creator>David Moles</dc:creator>
		<pubDate>Wed, 03 Jun 2009 09:08:41 +0000</pubDate>
		<guid isPermaLink="false">http://sarahtaraporewalla.com/thoughts/?p=204#comment-2970</guid>
		<description>So, I&#039;ve only done about half a project in Rails, mostly just to see how hard it would be for me to do it, and (in the end) to prod the couple of old-school Perl hackers who originally volunteered for the project into getting off the couch and writing some code.

But it seemed to me that the main advantage of Rails was that if I was willing to let the ORM model drive everything in both directions, Rails would happily take most persistence tasks and most of the &quot;C&quot; tasks in &quot;MVC&quot; (at least for basic use cases) off my plate. Unfortunately I was starting from a pre-existing database, so it wasn&#039;t quite that easy, but that seemed to be the general idea.

Since I come from a Java background, and I&#039;ve been through everything from SQL-in-the-JSP to entity beans to home-grown SQL abstraction libraries to Hibernate and back, I totally understand where you&#039;re coming from, about the model and the database evolving in different directions. But I guess what I&#039;m wondering is, how much of what&#039;s good about Rails do you keep, when you stop letting the ORM model drive?</description>
		<content:encoded><![CDATA[<p>So, I&#8217;ve only done about half a project in Rails, mostly just to see how hard it would be for me to do it, and (in the end) to prod the couple of old-school Perl hackers who originally volunteered for the project into getting off the couch and writing some code.</p>
<p>But it seemed to me that the main advantage of Rails was that if I was willing to let the ORM model drive everything in both directions, Rails would happily take most persistence tasks and most of the &#8220;C&#8221; tasks in &#8220;MVC&#8221; (at least for basic use cases) off my plate. Unfortunately I was starting from a pre-existing database, so it wasn&#8217;t quite that easy, but that seemed to be the general idea.</p>
<p>Since I come from a Java background, and I&#8217;ve been through everything from SQL-in-the-JSP to entity beans to home-grown SQL abstraction libraries to Hibernate and back, I totally understand where you&#8217;re coming from, about the model and the database evolving in different directions. But I guess what I&#8217;m wondering is, how much of what&#8217;s good about Rails do you keep, when you stop letting the ORM model drive?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Clinton Begin</title>
		<link>http://sarahtaraporewalla.com/thoughts/design/i-dont-believe-in-orm-object-as-your-domain-model/comment-page-1/#comment-2963</link>
		<dc:creator>Clinton Begin</dc:creator>
		<pubDate>Wed, 03 Jun 2009 03:51:51 +0000</pubDate>
		<guid isPermaLink="false">http://sarahtaraporewalla.com/thoughts/?p=204#comment-2963</guid>
		<description>Hi Sarah,

This is an interesting blog post for a couple of reasons.  First, because I think this is a phase all developers go through... that of over abstraction.  If you separate your domain model and your &quot;ORM model&quot;, and similarly you&#039;ll probably have a form model for your web framework because you&#039;ll eventually decide that you need a place to put lists of optional values or non-domain related form fields (e.g. &quot;remember my username&quot;).  Then you&#039;ll find yourself marshalling from the web to the form, loading domain objects, mapping them to orm objects, and finally persisting them to the database.  Then one day someone will want an XML format of your domain and you&#039;ll need to serialize it using XStream or something similar, but then where do you put your SOAP envelope?  PHEW!!!

Suddenly you&#039;ll have the 7 layer cake design that cost so many applications their success.  I saw Rails as the counter to this design, with its relatively flat design... the &quot;smart object&quot; design, where the domain is everything (from validations to web form fields, to mapped persistence fields etc).

Anyway .  The second reason I find your post interesting is that I agree with your statement that eventually, even if you begin with full control of your database, it ultimately diverges in its own direction.  This usually happens once your application is successful and people start to notice that your database contains useful information. And along comes &quot;Application B&quot; -- the other application or 3rd party tool that is built in some other language and expects completely different things of your database.  All of a sudden the database is no longer your own.  

So you&#039;re absolutely right to feel that disconnect early.  However, the solution of using two layers of classes might be overkill (or just &quot;kill&quot; or perhaps &quot;certain death&quot; ;-)  I fear you&#039;ll regret that decision in the long run.  

A better solution is probably just plain old SQL and a good domain model, and a web framework that lets you wrap natural domain objects with forms (like Stripes).  This keeps you to a single domain, a light web design and a flexible persistence solution.  And about half as much code as you&#039;re about to write.  :-)

I&#039;ve always said, a project may start with ORM, but it will end with SQL.  

All the best,

Clinton Begin
Former ThoughtWorker</description>
		<content:encoded><![CDATA[<p>Hi Sarah,</p>
<p>This is an interesting blog post for a couple of reasons.  First, because I think this is a phase all developers go through&#8230; that of over abstraction.  If you separate your domain model and your &#8220;ORM model&#8221;, and similarly you&#8217;ll probably have a form model for your web framework because you&#8217;ll eventually decide that you need a place to put lists of optional values or non-domain related form fields (e.g. &#8220;remember my username&#8221;).  Then you&#8217;ll find yourself marshalling from the web to the form, loading domain objects, mapping them to orm objects, and finally persisting them to the database.  Then one day someone will want an XML format of your domain and you&#8217;ll need to serialize it using XStream or something similar, but then where do you put your SOAP envelope?  PHEW!!!</p>
<p>Suddenly you&#8217;ll have the 7 layer cake design that cost so many applications their success.  I saw Rails as the counter to this design, with its relatively flat design&#8230; the &#8220;smart object&#8221; design, where the domain is everything (from validations to web form fields, to mapped persistence fields etc).</p>
<p>Anyway .  The second reason I find your post interesting is that I agree with your statement that eventually, even if you begin with full control of your database, it ultimately diverges in its own direction.  This usually happens once your application is successful and people start to notice that your database contains useful information. And along comes &#8220;Application B&#8221; &#8212; the other application or 3rd party tool that is built in some other language and expects completely different things of your database.  All of a sudden the database is no longer your own.  </p>
<p>So you&#8217;re absolutely right to feel that disconnect early.  However, the solution of using two layers of classes might be overkill (or just &#8220;kill&#8221; or perhaps &#8220;certain death&#8221; <img src='http://sarahtaraporewalla.com/thoughts/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />   I fear you&#8217;ll regret that decision in the long run.  </p>
<p>A better solution is probably just plain old SQL and a good domain model, and a web framework that lets you wrap natural domain objects with forms (like Stripes).  This keeps you to a single domain, a light web design and a flexible persistence solution.  And about half as much code as you&#8217;re about to write.  <img src='http://sarahtaraporewalla.com/thoughts/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>I&#8217;ve always said, a project may start with ORM, but it will end with SQL.  </p>
<p>All the best,</p>
<p>Clinton Begin<br />
Former ThoughtWorker</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Ron</title>
		<link>http://sarahtaraporewalla.com/thoughts/design/i-dont-believe-in-orm-object-as-your-domain-model/comment-page-1/#comment-2956</link>
		<dc:creator>David Ron</dc:creator>
		<pubDate>Tue, 02 Jun 2009 23:46:18 +0000</pubDate>
		<guid isPermaLink="false">http://sarahtaraporewalla.com/thoughts/?p=204#comment-2956</guid>
		<description>Some people like to evolve their databases to meet their domain, but it sounds like you don&#039;t like to refactor your database.
http://en.wikipedia.org/wiki/Database_refactoring

I think that you may have better luck using an object database than trying to slap a bunch of duct tape over relational database.</description>
		<content:encoded><![CDATA[<p>Some people like to evolve their databases to meet their domain, but it sounds like you don&#8217;t like to refactor your database.<br />
<a href="http://en.wikipedia.org/wiki/Database_refactoring" rel="nofollow">http://en.wikipedia.org/wiki/Database_refactoring</a></p>
<p>I think that you may have better luck using an object database than trying to slap a bunch of duct tape over relational database.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
