Why ORM?

14 May 2013 | java, ORM

Why use ORM?

The path to coding Nirvana is a long one. As you navigate these treacherous ways, you’ll find many corpses – of people who have died of SQL over-injection or of Object-Relational-Miscarriage. For those of you who’ve been doing object-relational stuff long enough and have scars in unmentionable places, go back to your drinks. For the rest of you, for whom ‘Why ORM?’ is an interview question, gather around and warm your toes by the electric light.

Seriously, why ORM?

Well, an Object-Relational-Mapping tool basically takes away the pain (perceived) of writing SQL. As object-oriented programmers, we tend to think in terms of objects.

“Goooo ORM!!!”, you say?

Wait. If the only reason you really like ORMs is that they help you avoid SQL, you will eventually be stuck up the proverbial creek without a paddle.

In short, if you have a simple project with a none-too-complex object model, use simple JDBC. If you have a complex domain model with ‘interesting’ relationships between the objects, use an ORM.

At some point, however, you will need to tune your application to cater to higher loads and replace some of that auto-generated SQL with something more efficient – which means that if you’re writing an application that uses a relational database you’d better !$@!%@#$% know SQL.

comments powered by Disqus

Older · View Archive (8)

Sorting a map by values

How to sort a map in Java by its values instead of by its keys.

Most applications of Maps do not require ordering. Occasionally, we stumble upon instances where maps need sorting. To maintain insertion order in Maps, use a LinkedHashMap. To sort on the keys, use a SortedMap.


Hibernate vs MyBatis

Comparison of MyBatis versus Hibernate

I’ve often heard people arguing about whether Hibernate is better or MyBatis. The truth is, “there is no spoon.” It is not about whether Hibernate is better or MyBatis, but which of these tools best fits your situation. Without further ado, here is a comparison.