What Java ORM Do You Prefer, and Why? SQL of Course!
Stack Overflow provides some insight into the ORM vs SQL debate.
Join the DZone community and get the full member experience.Join For Free
Catchy headline, yes. But check out this Stack Overflow question by user Mike:
(I’m duplicating it here as it might be deleted soon)
It’s a pretty open ended question. I’ll be starting out a new project and am looking at different ORMs to integrate with database access. Do you have any favorites? Are there any you would advise staying clear of?
And the top voted answer (164 points by David Crawshaw is: “Just use SQL”:
I have stopped using ORMs. The reason is not any great flaw in the concept. Hibernate works well. Instead, I have found that queries have low overhead and I can fit lots of complex logic into large SQL queries, and shift a lot of my processing into the database. So consider just using the JDBC package.
The second answer (66 points by user simon is, again: “Just use SQL”:
None, because having an ORM takes too much control away with small benefits. The time savings gained are easily blown away when you have to debug abnormalities resulting from the use of the ORM. Furthermore, ORMs discourage developers from learning SQL and how relational databases work and using this for their benefit.
The third answer (51 points by myself) is saying, once more: “Use SQL” (and use it with jOOQ).
The truth is, as we’ve shown numerous times on this blog: Hibernate/JPA/ORMs are good tools to get rid of boring (and complex) CRUD. But that’s just boilerplate logic with little value to your business logic. The interesting stuff—the queries, the batch and bulk processing, the analytics, the reporting, they’re all best done with SQL. Here are some additional articles:
- Turn Around. Don’t Use JPA’s loadgraph and fetchgraph Hints. Use SQL Instead.
- Java 8: No More Need for ORMs
- Type Safe Queries for JPA’s Native Query API
- NoSQL? No, SQL! – How to Calculate Running Totals
- 10 SQL Tricks That You Didn’t Think Were Possible
Stay tuned as we’re entering an era of programming where object orientation fades, and functional/declarative programming makes data processing extremely easy and lean again.
Published at DZone with permission of Lukas Eder, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.