A minimalist, good-enough approach to object-relational mapping

Everyone hates ORM.

But the truth is, decades after it was invented, we’re still talking about it. We still need it. There are few alternatives.

NoSQL notwithstanding, SQL databases remain a pretty good way to store data. And objects remain a pretty good way to represent and manipulate data. And there’s no getting around the fact that there’s an impedance mismatch.

If you’re writing in Java and talking to databases, you really have three main choices. You can use a big, complicated ORM like Hibernate. You can write direct calls to JDBC. Or you can try to get rid of some of the JDBC boilerplate by using one of the micro-ORMs.

Or you can do what I did and write your own micro-ORM which rips off the good ideas found in other ORMs.

I did it because, well, I just didn’t like the design of the micro-ORMs that I found. Too clunky, too this, too that. So I decided to start clean and appropriate the ideas in other ORMs that felt simple and elegant.

Here’s the theory behind this particular ORM:

First, SQL is really good. It’s battle-tested and does everything you need.

Second, JDBC is a drag, because it requires tons of repetitive code. JDBC was designed that way for a reason; someone, somewhere, had a legitimate need for each and every feature, and all that flexibility was necessary to accommodate everyone’s features. But it sure makes day-to-day work hard.

So a better ORM should make the simple things easy, and the hard things possible. Simple things should be done in one line of code. Hard things should be made possible by getting out of the way and allowing the programmer to drop into straight SQL when necessary. It’s the best of both worlds.

The result of this effort is Dieselpoint Norm. (I originally intended “Norm” to stand for “Not Object-Relational Mapping”, but that’s what it is, and it’s ok.)

Norm does the simple things well. You can perform a query in one line of code:

List<Person> people = db.where(“name=?”, “Bob”).results(Person.class);

You can perform other tasks with similarly minimalist code. The setup/configuration is also dirt simple: just provide the necessary JDBC connection parameters and you’re done.

The system will use existing JPA / Hibernate annotations (@Table, @Column, @Id, etc.) but doesn’t require them.

I’ve tried very hard to find the right balance between doing too much and doing too little. Too much and you get a steep learning curve. Too little and you hit brick walls. You can never be sure you’ve gotten it exactly right.

But we use this code in production in our SaaS enterprise search product at Dieselpoint and have been happy with it. It provides an interface over the control and coordination database. Works great.

We hope you find it worthwhile.

You can find Dieselpoint Norm on Github here.