Hierarchical data structures are frequently saved in relational databases. This type of storage is flexible but flat, therefore the tree structure needs to be build with every query. I wish to store forum posts like a tree structure, but it ought to be possible to question effectively, say for instance choosing posts by date or author.
Let me come with an free database that's accessible from Java.
What's the easiest method to achieve this? CouchDB? neo4j? ...?
Here is a great article on Neo4j. Generally, it appears like neo4j is the best choice since document databases continue to be relatively flat and can lead to some awkward setup (still possible though).
Neo4j, as being a graph database, ought to be a good fit for storing you tree. I have not used at all it, but given your condition domain, it appears prefer option (a minimum of the main one to research first).
So far as exactly what the "easiest wayInch is, I believe that is dependent in your implementation and needs. I believe you need to write an easy test against a graph database, a document database, an object database along with a relational database (or otherwise) and find out which fits the issue that you are attempting to solve.
Initially when i first experienced this issue, I have found the truly amazing article (link).
In tho words: in RDBMS world you will find 2 primary tree model storage approaches:
- The Adjacency List Model
- The Nested Set Model