Devlico.Us
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @devlicious

Jeff Perrin - Sexier Than You Are



Persistence Ignorance

People are talking about Microsoft's Entity framework and how it does not currently allow persistence ignorant domain objects.

I've been torn about this issue for a while now. On the one hand, having an O/R mapper that is persistent ignorant essentially means that it has to support XML mapping files. The downside to this approach is duplication of each entity's properties (which leads to managing them in multiple places), having to edit and maintain these files, and not being able to see mapping information all in one place. This price is often worth it, though.

On the other hand, using attributes to specify mapping information leads to less "code" to manage, and the advantage of having your domain class and mapping information all in one location. The price is that your domain objects have to know about the persistence framework.

The one thing I've observed recently is that most of the Java developers I've talked to who've used Hibernate in the past are excited and relieved that the latest versions support annotations (attributes in .NET) for specifying mapping information. Most of them seem to dislike mapping via XML files, and feel that the price of using annotations is worth it.

It's too bad for Microsoft that nHibernate already supports both methods, so they'll have to as well if they want to keep up.


Published Mar 14 2007, 07:53 PM by Jeff Perrin
Filed under: , ,

Comments

Christopher Bennage said:

I definitely find myself leaning toward attributes right now.  I agree with you about the duplication of properties.

However, (and I will confess the influence of <a href="http://en.wikipedia.org/wiki/Ruby_on_Rails#Philosophy">Ruby's convention over configuration</a>) I am considering the value of mapping based on naming conventions (supplemented by attributes for unusual conditions, or maybe even [sigh] a config file).  

What are your thoughts on that?

# March 15, 2007 8:15 AM

Christopher Bennage said:

I just thought of one objection. Mapping based on naming convention would make the database and the domain model too tightly coupled.

BTW, sorry for the html in the last post.  I forgot it's not supported.

# March 15, 2007 9:39 AM

Jeff Perrin said:

I personally enjoy attributes over XML, and am willing to give up persistence ignorance for them as well. As far as Ruby is concerned, the Rails folks have a huge advantage in that they *don't* map by convention... The database columns *are* the domain entity's properties. There is no mapping at all, it's just done automagically on the fly with method_missing and some dynamic code generation. Rails is 100% DRY when it comes to ActiveRecord.

# March 15, 2007 5:18 PM

About Jeff Perrin

Jeff is not an internationally (or even locally) known expert in anything related to software development. He holds no certifications worth speaking about, and didn't graduate from University. The value of anything written on his blog should be deemed suspect at the minimum, and blatantly false and misleading in the worst case. Don't let his innate sex appeal fool you... Jeff does not know anything about which he speaks. Check out Devlicio.us!

Our Sponsors

Red-Gate!