The ORM Debate: Experts Weigh In
The ORM Debate: Experts Weigh In
Join the DZone community and get the full member experience.Join For Free
Automist automates your software deliver experience. It's how modern teams deliver modern software.
A lot of controversy has been generated recently over blog posts "ORMs are a thing of the past" and (the more poetically titled) "A Farewell to ORMs". They have been fueling debates over the merits and shortfalls of ORMs. DZone contacted some developers who have worked with ORMs to weigh in on this issue.
Is the ORM becoming obsolete? Is it still a necessary tool? Share your stance in the comment box below.
Jesse Davis, a Senior Engineering Manager at DataDirect, is a JDBC expert and deeply understands the uses of ORM. "ORM's were created because they're easy. It exposes people to the SQL language," Davis said in an interview with DZone. He says that people will always run into more problems as they add more layers of abstraction on top of boilerplate code. He admits that some of the things in the anti-ORM blogs are true, but that ORMs are far from a thing of the past. "Be aware of why you need the technology," he says.
Davis says more about ORMs in his interview with DZone's Nitin Bharti:
"With the ORM, the programming style is just different. So it's mostly a matter of taste. Some would argue that it's a matter of power, but I think it's mostly taste. And when you come down to it, the ORM model is an excellent model when designing for very complex systems.
But in order to use an ORM, you're going to have to live with some sacrifices. You're going to have to sacrifice some performance because again, an ORM is useless without data connectivity. And so the ORM is built on top of the driver. Again you have the ability and the query language - I'll take JPQL for instance. It's an object-based query language. So you can query your objects but when that object model gets down to the wire level, it still has to be translated into a SQL statement before going into the database. And so you have to live with giving up a little bit of your control of your SQL statements in order to use the more ease-of-use features of an ORM model."
Emmanuel Bernard, a JBoss lead developer on the Hibernate team, also talked to DZone about ORMs and had this to say:
"Let's start with the fundamentals, RDBMS are not going anywhere anytime soon. All the hype about NoSQL is just the expression of niche markets where RDBMS have their limits and where better tools can be found.
While Facebook, twitter and the like might find relational databases limiting due to scalability issues, remember that 99.999% of applications out there do not need to scale anywhere near a hundredth of what these sites are experiencing.
Now, provided that SQL is not going anywhere, ORMs are not going anywhere. Thus far, they have proven to be the most effective way to access your relational database 95% of the time both from a performance point of view and from a code simplification PoV. Of course, like any tools, don't use it where it does not make sense. In some applications, plain SQL is easier.
To answer specific questions raised by "ORM's are a thing of the past":
- Correct, there is a learning curve to ORMs but standardization like JPA has increased the overall population knowledge. Plus, in most teams, one person knowledgeable in SQL and ORMs is enough to counter-balance most ORM problem or misuse.
- State transfer and management is a complex topic and LazyInitializationException is a symptom of this. State management frameworks have grown out of this problem like Seam or JSR-299 CDI by looking at the bigger picture rather than blame the messenger. They are here to globally address the problem of state management and state transfer. You won't get any LazyInitializationException if you play within their paradigms.
ORM is about updating your database and querying your data automatically and in an optimized way for 95% of your use cases.
For the 5% remaining, go with raw SQL. Your mileage may vary depending on the ORM, but if for example you are massively inserting / updating data, you are usually best done in plain SQL rather than with a traditional ORM. But it's just common sense vs abuse of a tool."
Bernard said the alternative to using ORM was to "Painfully write all your SQL statements and be beaten down by your DBA for characterized query inefficiency. Instead of having optimized queries 95% of the time and work with your SQL expert for 5% of them, you will have to rely on him for 40% of your queries."
What is your opinion of ORMs? Are they going to stick around or will they soon become extinct? We want your position.
Opinions expressed by DZone contributors are their own.