Are ORMs Really a Thing of the Past?
Stephan Schmidt has blogged on the ORMs being a thing of the past. While he emphasizes on ORMs' performance concerns and dismisses them as leaky abstractions that throw LazyInitializationException, he does not present any concrete alternative. In his concluding section on alternatives he mentions ..
"What about less boiler plate code due to ORMs? Good DAOs with standard CRUD implementations help there. Just use Spring JDBC for databases. Or use Scala with closures instead of templates. A generic base dao will provide create, read, update and delete operations. With much less magic than the ORM does."
Unfortunately, all these things work on small projects with a few number of tables. Throw in a large project with a complex domain model, requirements for relational persistence and the usual stacks of requirements that today's enterprise applications offer, you will soon discover that your home made less boilerplated stuff goes for a toss. In most cases you will end up either rolling out your own ORM or start building a concoction of domain models invaded with indelible concerns of persistence. In the former case, obviously your ORM will not be as performant or efficient as the likes of Hibernate. And in the latter case, either you will end up building an ActiveRecord model with the domain object mirroring your relational table or you may be more unfortunate with a bigger unmanageable bloat.
It's very true that none of the ORMs in the market today are without their pains. You need to know their internals in order to make them generate efficient queries, you need to understand all the nuances to make use of their caching behaviors and above all you need to manage all the reams of jars that they come with.
Yet,
in the Java stack, Hibernate and JPA are still the best of options when
we talk about big persistent domain models. Here are my points in
support of this claim ..
- If you are not designing an ActiveRecord based model, it's of paramount importance that you keep your domain model decoupled from the persistent model. And ORMs offer the most pragmatic way towards this approach. I know people will say that it's indeed difficult to achieve this in a real life world and in typical situations compromises need to be made. Yet, I think if you need to make compromise for performance or whatever reasons, it's only an exception. Ultimately you will find that the mjority of your domain model is decoupled enough for a clean evolution.
- ORMs save you from writing tons of SQL code. This is one of the compelling advantages that I have found with an ORM that my Java code is not littered with SQL that's impossible to refactor when my schema changes. Again, there will be situations when your ORM may not churn out the best of optimized SQLs and you will have to do that manually. But, as I said before, it's an exception and decisions cannot be made based on exceptions only.
- ORMs help you virtualize your data layer. And this can have huge gains in your scalability aspect. Have a look at how grids like Terracotta can use distributed caches like EhCache to scale out your data layer seamlessly. Without the virtualization of the ORM, you may still achieve scalability using vendor specific data grids. But this comes at the price of lots of $$ and the vendor lock-ins.
Stephan also feels that the future of ORMs will be jeopardized because of the advent of polyglot persistence and nosql data stores. The fact is that the use cases that nosql datastores address are very much orthogonal to those served by the relational databases. Key/value lookups with semi-structured data, eventual consistency, efficient processing of web scale networked data backed with the power of map/reduce paradigms are not something that your online transactional enterprise application with strict requirements of ACID will comply with. So long we have been trying to shoehorn every form of data processing with a single hammer of relational databases. It's indeed very refreshing to see the onset of nosql paradigm and it being already in use in production systems. But ORMs will still have their roles to play in the complementary set of use cases.
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)






Comments
Mark Thornton replied on Mon, 2009/10/19 - 3:54am
Michal Jemala replied on Mon, 2009/10/19 - 6:15am
Ovidiu Guse replied on Mon, 2009/10/19 - 6:52am
"I believe that plain object persistence wihout any need to transform an OO model into the realational tables will gain on popularity very soon..hope so :-)"
You know ... that was before, the starting point of ORM ... :).
I agree with Debasish.
Artur Sobierajczyk replied on Mon, 2009/10/19 - 12:41pm
Marc Stock replied on Mon, 2009/10/19 - 2:13pm
cowwoc replied on Mon, 2009/10/19 - 4:51pm
The author argues that as your domain model grows ORMs become more and more attractive. I'd actually argue the opposite. ORMs work fine for trivial object mappings but as your project grows you end up finding what Ted Neward blogged about so well: http://blogs.tedneward.com/2006/06/26/The+Vietnam+Of+Computer+Science.aspx
Leaky abstractions are *extremely* painful. The more I deal with ORMs the more I hate them. I don't know what the solution is, but I can tell you ORMs are not it. Perhaps Object-Oriented DBs are the solution, perhaps not. I'd personally prefer spending my time working around OODBM flaws than around ORM flaws. At least OODBMs like http://www.neodatis.org/ let me work with clean object designs first and optimize second. ORMs seem to have it the wrong way around.
Andy Jefferson replied on Tue, 2009/10/20 - 1:46am
Whatever the database you choose, for whatever reasons, you should be able to use the same object-oriented API for persistence and retrieval of Java objects. Which is why DataNucleus provides persistence to RDBMS, ODBMS, HBase (HADOOP), Amazon S3, Google BigTable, XML, Excel, ODF, JSON, LDAP using standards-based persistence APIs. Hence swapping datastores at a later date becomes trivial.
Mladen Girazovski replied on Wed, 2009/10/21 - 5:22am
Yep, people say ORM but they mean Hibernate, almost any Blog here rerefering to ORM talks about Hibernate (which ist outdated in many aspects) and is therefore misslabeled, including this blog.
George Farmer replied on Wed, 2009/10/21 - 2:16pm
in response to:
Andy Jefferson
Andy Jefferson replied on Wed, 2009/10/21 - 3:43pm
in response to:
George Farmer
George Farmer replied on Wed, 2009/10/21 - 4:02pm
in response to:
Andy Jefferson
Mark Unknown replied on Wed, 2009/10/21 - 7:52pm
in response to:
cowwoc
Hmm. I must be blind and stupid because as my projects grows I am SO glad I am using an ORM. I am not sure what Ted was talking about. He might be smart, but he is not always right.
Are ORMs pefect? No. Would an ODBMS be better? Possibly.
Mark Unknown replied on Wed, 2009/10/21 - 8:00pm
in response to:
George Farmer
Mark Unknown replied on Wed, 2009/10/21 - 8:03pm
in response to:
Artur Sobierajczyk
"Machine language isn't a low-level implementation for high level languages"
Mark Unknown replied on Wed, 2009/10/21 - 8:04pm
in response to:
Mark Thornton
What compromise?
Andy Jefferson replied on Thu, 2009/10/22 - 12:05am
in response to:
George Farmer
"Come on" ? Now it "takes a while" ... previously you said it was impossible.
If you have persistence metadata for persisting to RDBMS and then want to go to another datastore then you can clearly do it, subject to what the other datastore plugin supports at that time. Since you pick a plugin that is immature still (and labelled beta FYI) then there are always going to be things that aren't fully supported; when Google finally dedicate resource to their DataNucleus BigTable plugin then they will support the vast majority of ORM metadata components. If you had picked a mature plugin, like say XML, or NeoDatis, then the persistence would work with very little to do.
George Farmer replied on Thu, 2009/10/22 - 9:45am
in response to:
Andy Jefferson
Alexander Ashitkin replied on Sun, 2009/11/08 - 2:17pm