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.

4 thoughts on “Persistence Ignorance

  1. Ayende Rahien

    It is certainly a LOT easier to have it done via attributes, but it is essential that it won’t be done _just_ with attributes.
    The Microsoft approach a the moment seems to require BOTH attributes and multiply XML files.

  2. Simon

    It’s funny how things go around in circle. I thought one of the main purposes of using XML is to separate configuration out of the source code. Annotation will become source code in a different form. Next thing you know you’ll end up with more annotation than the actual code. People will start whining again.

  3. Mats Helander

    Specifying your mapping meta data with attributes can be kind of convenient, but one good thing with using xml is that it is easier to use a specialized tool for creating and maintaining it, which won’t have to try to mess about with your code files, adding attributes to them.

    NPersist also supports both attributes and xml nowadays, since the best way is obviously to have the option to decide for yourself which you prefer, but I have to agree with Simon that it probably won’t take long until code files have more attributes than code in them, so in my opinion the xml files are still the better way to go.