Hierarchical data structures are often stored in relational databases. This kind of storage is flexible but flat, so the tree structure has to be build with each query. I want to store forum posts as a tree structure, but it should be possible to query efficiently, say for example selecting posts by date or author.

I'd like to have an open source database that is accessible from Java.

What is the best way to do so? CouchDB? neo4j? ...?