To ORM or not to?


I noticed that there is this very strong love / hate relationship with Object Relationship Mapping (ORM) among developers. Some love it for the convenience it gives and some hate it with a passion with its crazy overheads.

I used to work with a company who don’t use ORM, so every data CRUD uses sql queries, including simple queries “select column1, column2 from sometable”. All data inputs have to be sanitized by using escape string. As someone who is accustomed to using CakePHP and Hibernate, it is a pain to use queries to just to do inserts or deletes of data.

But then the company have queries that inner join more than 5 tables on the database. On top of that, the database uses composite keys as primary keys extensively. Hence ORM doesn’t work that well.

My point of view is this: ORMs are good for simple, general and generic queries like simple insert or delete of data. It helps to take a load off developers who have to type “insert into …. values…..” for every single query. for complex queries that are unique to the type of SQL database that you use (like mysql insert on duplicate keys update, Oracle’s merge into) it is better off that you use a query string instead. Also for queries that have to join or ‘=’ to a lot of tables. Hence I see it as 80/20. 80% ORM for general queries and 20% for very niche queries to optimized performance.

Another example I would like to share is that I am creating a webapp using CakePHP, but invoice generation is in BIRT. In this setup I am unable to use CakePHP ORM onto BIRT, hence I use layman queries for BIRT. You may argue that I can use Hibernate for BIRT, but well, BIRT have enough overheads by itself, thanks to Java :p

Feel free to share your feelings about Object Relations Mapping here. Would be appreciated.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s