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.
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.
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.