Object Relational Mappers are evil (a meditation)

Steve Holden steve at holdenweb.com
Tue Oct 6 05:09:03 CEST 2009


Diez B. Roggisch wrote:
> Aaron Watters schrieb:
>> This is a bit off topic except that many Python
>> programmers seem to be allergic to typing SQL.
>>
>> RESOLVED:  Using ORMs leads lazy programmers
>> to make bad database designs.  It's better to
>> carefully design your database with no invisible
>> means of support and there is no reason to not
>> use SQL directly for this purpose.
>>
>> FOR EXAMPLE:  Consider blogging.  The most
>> successful blog software is WORDPRESS.  Here
>> is the WordPress data model:
>>
>> http://blog.kapish.co.in/wp-content/uploads/2009/03/wp_2.7.png
>>
>> Beautiful, isn't it?  It was designed by people who
>> thought about what they were doing and did it carefully.
>>
>> Now let's look at the Sakai Blogger tool data model
>> (as reverse engineered by someone who had to
>> fix a bug -- there actually was no data design created
>> by the implementers):
>>
>> confluence.sakaiproject.org/download/attachments/17072138/
>> entitymodel.pdf
>>
>> How did the above happen?  I suspect someone opened
>> up Eclipse and started typing, relying on the Hibernate
>> ORM to handle all the database stuff automagically.  The
>> result is a massive headache for people like me.  Another
>> one.  I routinely open up the mysql prompt and start typing
>> "show tables", "describe table blah", "select * from blah limit 10"...
>> trying to figure out WTF Hibernate did with my data.
> 
> I think your example is nonsense. Just comparing the two models based on
> "they both are for blogging" is like comparing a cessna to a 747 - yes,
> both are flying, but that's pretty much what they have in common.
> 
> It is pretty clear that sakai's data-model caters to a very
> sophisticated *user*-model, with roles and permissions, and whatnot.
> Plus other features. So it appears to be more in the CMS-league.
> 
It's also pretty clear that the person who developed the sakai map had
nothing to guide them, making it difficult to divine any structural
regularity that may be present in the design. The entity-relationship
diagram doesn't even show the cardinality of the relationships, making
it much less useful than it otherwise might be.

As a result the whole thing looks like a dog's breakfast.

> Now it's obviously easy to argue that this isn't needed for a simple
> blog. Nonetheless, it doesn't make a point about ORM. With any ORM I
> know (both in Java and Python) you could design the simple and straight
> model WP uses.
> 
> And I've seen my fair share of convoluted, trashy pure-SQL-based DBs as
> well.
> 
Yup, me too. Many such designs make mistakes like using multiple columns
(or, even worse, comma-separated values) instead of many-to-many
relationships. Sad how such elegant tools are so badly abused so often,
isn't it?

> So I think to make your point you need some more convincing arguments.
> 
It seems to me that the biggest sin in databases is a failure to use
rigorous design techniques. If somebody doesn't understand relational
theory then they will probably not design database representations that
are easy to work with. If they do understand then the designs they
produce will operate just as easily with object relational mappers as
they do with direct SQL.

I suspect Aaron was really complaining about ignorance rather than
laziness (though the two do sometimes go together, and the former is
often but by no means invariably caused by the latter). But he'd have to
confirm or deny that.

regards
 Steve
-- 
Steve Holden           +1 571 484 6266   +1 800 494 3119
Holden Web LLC                 http://www.holdenweb.com/
Watch PyCon on video now!          http://pycon.blip.tv/




More information about the Python-list mailing list