Prevayler: Hope or Hype?
I’ve been mucking about in the realm of Java and Object-Relational Mapping (ORM) lately, and there are a lot of choices out there. Hibernate, Castor, and a bevy of lesser-knowns.
The thing is, all I really need is to persist some java objects across runtime sessions. I don’t need to do data mining. I don’t need to do reporting. I don’t have bazillions of objects. I don’t need to have more than one application getting my data from a central location. Oh, and I really don’t want to have to design a database schema and create an XML mapping structure to move the data into persistence. I just want my Plain Old Java Objects (POJO’s) to be saved between application runs. Better yet, I’d like to be able to do transactional updates at runtime to keep the persistent versions up to date.
So I stumbled across Prevayler the other day. It looked reasonably simple, so I downloaded the jar and tried it out. Literally within minutes I was using Prevayler to transactionally persist a wrapped HashMap of my business objects to disk. This was by far the fastest, easiest mechanism I’ve ever used to persist objects across runtimes, bar none.
The Technical
My wrapped HashMap, in Prevayler terms, became my “Prevalent System.” Think of this as a loose analog to a database table with two columns: the HashMap’s key, and the HashMap’s value. For my purposes, the key is a GUID that I generate, and the value is my business object.
Any updates to the Prevalent System (adding, removing business objects) are done by implementing a Transaction interface or a QueryWithTransaction interface. These follow the Command Pattern to encapsulate the HashMap.put() or HashMap.remove() method calls. Again, really simple.
How does it work?
- The Prevalent System is kept in memory. I only have a few thousand business objects to put in my HashMap, so this is fine. If you have too many persistent data objects to keep in memory, then don’t use Prevayler.
- The initial state of the HashMap is written to disk using regular object serialization.
- Any transactions executed are also written to disk using object serialization before they are applied to the HashMap in memory. Essentially, these are the logical deltas of any modifications (additions, removals) I make. These “writes” are serialized, but are generally sub-millisecond in my implementation.
- Any “queries” to the Prevalent System (ie: give me business object X) are also done via the Command Pattern implementing a Query interface. These “reads” can be done concurrently, so the performance of HashMap.get() is what you’d expect from a non-persistent HashMap.
And that’s about it. For my needs (no reporting, no data mining, access by one application), it does exactly what I needed. If I needed those things, I’d probably go with Hibernate or some other means to map Java object fields to database records. But since I don’t, Prevayler is an easy win for me.
The Philosophical
Google Prevayler and you’re going to see equal parts zeal and bile. There is a decent Prevayler documentation site out there, but it isn’t very well promoted. The highly-visible sites that talk about Prevayler are largely polarized between folks who either think databases are for the weak or Prevayler is for the stupid. I don’t think either is true, but the negative publicity is certainly overwhelming. Prevayler needs a PR makeover in the very least.
In the meantime, it’s a simple, interesting approach to persistence. It’s easy enough to play with, so I encourage anyone with an hour to spare to give Prevayler a spin. The good news is that it is open source, so if you don’t like how it manages transactions, you can change it. My hope is that the Prevayler folks do a better job at promoting level-headed technical discussion and documention to counteract the p*ssing matches that invariably ensue in public forums. Telling people that “databases are dead” tends to turn people off, and for good reason.
More Info
Readily-available info about Prevayler isn’t promoted that well, so I’m keeping a del.icio.us index of some of the more informational stuff out there:
http://del.icio.us/mwoodman/prevayler
Hopefully some of the more technical resources out there will begin to gain visibility. I think as more people can examine Prevayler with honesty about strengths and weaknesses, the credibility of the project will improve.
Lets hope that cooler heads will, well, prevayl.


March 12th, 2005 at 18:58
I have the same problem with Prevayler, though, that I have with Hibernate’s auto-mode: I shouldn’t have to give up SQL access to the database. The thing is, from your perspective all you want to do is persist some objects and get them back later, but that is basically backing yourself into a corner. You never know when you might want to do a report or share that data with a PHP app.
March 14th, 2005 at 10:57
I agree with the potential for painting yourself in a corner, although I suspect that may be more of a mental corner than a “oh crap, there’s no way we can change our code now” corner. (Especially if you use a DAO layer to protect yourself from persistence details.)
My experience with Prevayler thus far has been how absolutely trivial it is to persist stuff. If I eventually have to toss Prevayler in favor of mapping objects into an RDBMS, I’ll have lost relatively little invested time.
June 3rd, 2005 at 05:50
If in memory persistancy of Prevayler type should be done using “Persisted Object Tree” is prefered.
Its the same ram shit idea but gives evan more freedom to the devel when creating is data objects.
Any way thats what i think! Also using none RDBMS for relatinal data is just crazy!
June 3rd, 2005 at 05:52
Ops! forgat the url pot.forgeahead.hu