Archive for the ‘hibernate’ Category

Pre-fetching in Rails

Thursday, May 24th, 2007

Pre-fetching, firing off a query just to fill up the first level cache, is a classic Hibernate optimization. You can now also do it in Rails with
this plugin
. This fills a gap when outer join fetching becomes too complex or the cartesian product bites you (the result of outer joins is the cartesian product of all involved tables, which grows exponentially).

Gavin King killed Prevayler

Friday, November 18th, 2005

The topic of Prevayler has once again popped up on javablogs.com so I’d thought I’d just give my current opinion on the subject.

Prevayler caught my interest about three years ago. I had written a couple of systems with EJB and was quite disillusioned about that particular technology. I was just starting a new project at Lecando and we were completely reevaluating our technology stack. The state of O/R-mappers in Java land was pretty sad back then. We tried out both OJB and Hibernate and neither of them were even close to acceptable quality. Both of the commercial options were ridiculously expensive so we didn’t even consider them. So we were about to do what most other projects did back then, write our own. Again! One morning one of the developers discovered Prevayler and we thought: what the heck, let’s give it a try. We had very good test coverage and were confident that we could replace it later down the line if needed too.

It was great! Not only was the performance amazing it was also incredibly productive. Prevayler wasn’t completely without it’s problems but we worked them out. The backsides of Prevayler are well known: it’s basically single threaded which means you can’t do any blocking I/O inside a Prevayler transaction and the data sizes you can use are quite limited (in practice a few 100 megabytes is the limit at the moment), there’s also the “Prevayler baptism problem” which affects how you code things a little bit. We understood all that and for the app we were writing we could live with it. Prevayler isn’t for everyone but it worked out well for us.

But the O/R-mapping landscape for Java didn’t stand still. Martin Fowler and David Rice published their patterns around O/R-mapping and of course Gavin King stepped up to the plate.

…and completely changed everything.

Both Hibernate and Rails’ ActiveRecord are today incredibly easy to use, productive and free. In fact they’re so easy to use and productive that there is very little need for Prevayler anymore. As I mentioned above there are some issues with developing and designing with Prevayler and of course there are some issues around O/R-mapping as well. With Hibernate/ActiveRecord you need to decide how to do your outer join fetching, how to set up your indexes and sometimes you might need to do some denormalizations. Hibernate can handle almost every performance problem I’ve seen within the framework where as in ActiveRecord you need to fall back on custom SQL on rare occasions. So there are issues around coding with both Prevayler and O/R-mapping but the advantages with O/R-mapping are pretty obvious: it can scale to almost any dimensions both in terms of load and data sizes.

So, Gavin King, you killed Prevayler. That’s fine, you did also change the world. (If you just wouldn’t be so incredibly smug about it. ;-) )