The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

O/R Mapping

I was wondering if someone can explain when utilizing OR mapping frameworks can be helpful and when it should be avoided? Would it make sense to use such layer of abstraction between objects and records in a system that DB schema's are not frequently changed/augmented?

Thank You
Tuesday, January 30, 2007
Its helpful by seperating out concerns and letting you write more modular, reusable, and focused code. Some of the more powerful ones provide a lot of DB optimizations and make it easy to change database venders. By having a DB layer, you can also change the ORM framework easier (e.g. a coworker wrote a code generator to migrate our SQL2Java to Hibernate).

Depending on the framework, you get more overhead. You're basically weighing time spent now versus more time later. In your case, a simpler ORM like SQL2Java is worthwhile. It generates the boilerplate class/manager against a DB table and lets you write custom SQL as needed.  That'll give you seperation and makes life easier, and you can migrate to a powerful ORM when needed.
Wednesday, January 31, 2007
You only need an OR mapper when the structure of your in-memory object (business layer or model) is diffeent from the structure of your relational database, which is (or should be) accessed through a separate Data Access Object (DAO). The mapper then has to deal with these differences in structure when the business layer communicates with the data access layer.

This to me is an unnecessary level of complexity with an unnecessary overhead. I avoid it completely by having a separate business layer object for each database table, so each object has exactly the same structure as its database table. Because the two structures are the same I do not need any extra software to deal with the differences.

Changing a table's structure is no big deal - I import the changed structure into my data dictionary, then press a button to regenerate the structure file in my application.

I have a separate DAO for MySQL, PostgreSQL and Oracle, so I can switch from one DBMS to another by changing one line in a config file.
Tony Marston Send private email
Wednesday, January 31, 2007
As with all frameworks, you need to weigh the effort to learn the framework and to make it do the things you need to do (especially in the "edge" cases that the framework doesn't support well), against the effort that it's saving you.

So far, I haven't seen the need to use an ORM framework based on this analysis. Like Tony suggests, I keep my database design in sync with my object model and use a layered design to encapsulate the actual database operations.

I always look first to simplify or eliminate a problem (object/relational mismatch) rather than to a complex way of solvng it.

my 2c
Mike S Send private email
Wednesday, January 31, 2007
+1 Tony.

I've encountered developers who insist O/R mapping is required with every project, and some who go further by insisting on Hibernate.  I'm sure there are times when it is necessary, but for a lot of stuff I do it seems like more of a hinderance than help.

Anyway, has anyone ever looked at or considered SimpleORM?  I saw it in a publication a while back.  It seems pretty lightweight, though I haven't used it myself... yet.
Wednesday, January 31, 2007
@Tony & Mike
We eliminated 90% of DAO code using Gentle.Net ORM. And we are portable over some 9 databases that Gentle can access, and since it's open source, you can quite easily build mapper for COBOL or any other database system that is not yet supported.
Small, simple, much easier to config then NHibernate.
Wednesday, January 31, 2007
I have read estimates that the data access layer accounts for approximately 30% of an application's code. Using an ORM you can nearly eliminate the need for a data access layer. Who would not want to eliminate that redundant 30% of code? I will never go back to life before ORM.
Liam McLennan Send private email
Monday, February 05, 2007
I use MyGeneration to create code. Not only am I spared of writing most of my basic crud statements, but I also get highly customizable and extensible database abstraction layer with strongly typed collections.

Ruby on Rails and Python with Django default on their own ORM frameworks. Many people who use Java will not code if they cannot use their Hibernate. Although ORM will not help you every single time it will definitely make your life easier most of the time.

It takes a bit of patience and time to getting used to it, but odds are that once that you begin using an ORM you will never look back.
Adolfo J. Peña (adolfojp) Send private email
Wednesday, February 07, 2007

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
Powered by FogBugz