Open debate: are persistent collections a necessity or a feature?
Over the past few days, Lukáš Bartoň and I have been discussing whether persistent collection mapping is a necessity or a feature in ORM tools. It all began with Hibernate co-author Christian Bauer's article Persistent collections are a feature!, which tries to clarify what Hibernate intends with collection mapping.
First, you really can use an ORM tool without mapping collections, which most developers do not realize at first. You can replace a collection fairly easily with a query. Instead of Hibernate fetching a child collection for you automatically, you write the same query by hand.
In my view, skipping collection mappings costs you one of the main reasons to use an ORM tool. That appeal is the convenience of working with persistent data without writing the boilerplate for communicating with a persistent store. I mainly mean the bridge between the object and relational worlds.
It feels natural to call parent.getChildren() and get all the children of that parent. It feels just as natural to add a new child with a simple call to parent.getChildren().add(child). I certainly do not see this as a bit of syntactic sugar that happens to be a nice ORM feature. My view is that every ORM tool absolutely has to behave this way. Without it, ORM tools lose their appeal and charm.
Christian Bauer and Gavin King, Java Persistence with Hibernate
One of the reasons you use a full object/relational mapping tool like Hibernate is, of course, that you don’t want to write that query.
Related articles
Related CZ Podcast episodes
- #3 · Java 6 SE, Vývoj webových aplikací
Dagi and Filemon discuss Java 6 and web application frameworks. · Czech audio
- #1 · Vývojová prostředí v Javě
The first CZ Podcast episode looks at Java development environments. · Czech audio