How to store tree structures in Java?

deamon picture deamon · Mar 9, 2010 · Viewed 7.4k times · Source

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? ...?

Answer

Yuri.Bulkin picture Yuri.Bulkin · Mar 9, 2010

When I first encountered this problem, I've found the great article (link).

In tho words: in RDBMS world there are 2 main tree model storage approaches:

  • The Adjacency List Model
  • The Nested Set Model